// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.elasticsan.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.elasticsan.models.Action;
import com.azure.resourcemanager.elasticsan.models.NetworkRuleSet;
import com.azure.resourcemanager.elasticsan.models.VirtualNetworkRule;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class NetworkRuleSetTests {
    @Test
    public void testDeserialize() {
        NetworkRuleSet model =
            BinaryData
                .fromString(
                    "{\"virtualNetworkRules\":[{\"id\":\"nxqbzvddn\",\"action\":\"Allow\",\"state\":\"networkSourceDeleted\"},{\"id\":\"icbtwnpzao\",\"action\":\"Allow\",\"state\":\"provisioning\"},{\"id\":\"hcffcyddglmjthjq\",\"action\":\"Allow\",\"state\":\"networkSourceDeleted\"},{\"id\":\"icxm\",\"action\":\"Allow\",\"state\":\"deprovisioning\"}]}")
                .toObject(NetworkRuleSet.class);
        Assertions.assertEquals("nxqbzvddn", model.virtualNetworkRules().get(0).virtualNetworkResourceId());
        Assertions.assertEquals(Action.ALLOW, model.virtualNetworkRules().get(0).action());
    }

    @Test
    public void testSerialize() {
        NetworkRuleSet model =
            new NetworkRuleSet()
                .withVirtualNetworkRules(
                    Arrays
                        .asList(
                            new VirtualNetworkRule().withVirtualNetworkResourceId("nxqbzvddn").withAction(Action.ALLOW),
                            new VirtualNetworkRule()
                                .withVirtualNetworkResourceId("icbtwnpzao")
                                .withAction(Action.ALLOW),
                            new VirtualNetworkRule()
                                .withVirtualNetworkResourceId("hcffcyddglmjthjq")
                                .withAction(Action.ALLOW),
                            new VirtualNetworkRule().withVirtualNetworkResourceId("icxm").withAction(Action.ALLOW)));
        model = BinaryData.fromObject(model).toObject(NetworkRuleSet.class);
        Assertions.assertEquals("nxqbzvddn", model.virtualNetworkRules().get(0).virtualNetworkResourceId());
        Assertions.assertEquals(Action.ALLOW, model.virtualNetworkRules().get(0).action());
    }
}
