Ejemplo n.º 1
0
        public void TestEquality()
        {
            Assert.Equal(Module2, Module2);
            Assert.Equal(Module2, Module8);
            Assert.Equal(Module2, Module9);
            Assert.Equal(Module9, Module2);
            Assert.Equal(Module1, Module9);
            Assert.Equal(Module9, Module1);

            Assert.NotEqual(Module1, Module2);
            Assert.NotEqual(Module2, Module3);
            Assert.NotEqual(Module2, Module4);
            Assert.NotEqual(Module2, Module5);
            Assert.NotEqual(Module2, Module6);
            Assert.NotEqual(Module2, Module7);
            Assert.NotEqual(Module8, Module10);
            Assert.NotEqual(Module8, Module11);
            Assert.NotEqual(Module8, Module12);
            Assert.NotEqual(Module8, Module13);

            Assert.False(Module1.Equals(null));
            Assert.False(Module2.Equals(null));

            Assert.False(Module1.Equals(new object()));
            Assert.False(Module2.Equals(new object()));
        }
Ejemplo n.º 2
0
        public void TestEquality()
        {
            Assert.Equal(Module1, Module1);
            Assert.Equal(Module1, Module2);
            Assert.Equal(Module8, Module8);
            Assert.NotEqual(Module1, Module3);
            Assert.NotEqual(Module1, Module9);
            Assert.NotEqual(Module1, Module11);
            Assert.NotEqual(Module1, Module4);
            Assert.NotEqual(Module1, Module6);
            Assert.NotEqual(Module1, Module7);
            Assert.Equal(Module1, Module8);
            Assert.Equal(Module9, ModuleWithConfig);
            Assert.NotEqual(Module1, Module10);

            Assert.False(Module1.Equals(null));
            Assert.False(Module8.Equals(null));

            Assert.True(Module1.Equals(Module1));
            Assert.False(Module1.Equals(Module3));

            Assert.False(Module1.Equals((object)null));
            Assert.False(Module8.Equals((object)null));
            Assert.True(Module1.Equals((object)Module1));
            Assert.True(Module1.Equals((object)Module2));
            Assert.False(Module1.Equals((object)Module3));
            Assert.False(Module1.Equals(new object()));
            Assert.True(Module1.Equals((IModule <DockerConfig>)Module1));

            Assert.Equal(Module1.GetHashCode(), Module2.GetHashCode());
            Assert.NotEqual(Module1.GetHashCode(), Module3.GetHashCode());
            Assert.NotEqual(Module1.GetHashCode(), Module9.GetHashCode());
            Assert.NotEqual(Module1.GetHashCode(), Module11.GetHashCode());
        }
Ejemplo n.º 3
0
        public void TestSerialize()
        {
            string  jsonFromTestModule         = ModuleSerde.Instance.Serialize(Module8);
            var     myModule                   = ModuleSerde.Instance.Deserialize <TestModule>(jsonFromTestModule);
            IModule moduleFromSerializedModule = ModuleSerde.Instance.Deserialize <TestModule>(serializedModule);

            myModule.Name = "mod1";
            moduleFromSerializedModule.Name = "mod1";

            Assert.True(Module8.Equals(myModule));
            Assert.True(moduleFromSerializedModule.Equals(Module8));
            Assert.True(moduleFromSerializedModule.Equals(Module1));
        }
Ejemplo n.º 4
0
        public void TestDeserializeValidJson(string inputJson)
        {
            var module = ModuleSerde.Instance.Deserialize <TestModule>(inputJson);

            module.Name = "<module_name>";
            Assert.True(ValidJsonModule.Equals(module));
        }
Ejemplo n.º 5
0
        public void ModuleSetSerialize()
        {
            var serializerInputTable = new Dictionary <string, Type>()
            {
                { "test", typeof(TestModule) }
            };
            var myModuleSetSerde = new ModuleSetSerde(serializerInputTable);

            string jsonFromTestModuleSet  = myModuleSetSerde.Serialize(ModuleSet1);
            string jsonFromTestModuleSet2 = myModuleSetSerde.Serialize(ModuleSet2);

            ModuleSet myModuleSet  = myModuleSetSerde.Deserialize(jsonFromTestModuleSet);
            ModuleSet myModuleSet2 = myModuleSetSerde.Deserialize(jsonFromTestModuleSet2);

            IModule module1 = ModuleSet1.Modules["mod1"];
            IModule module2 = myModuleSet.Modules["mod1"];

            IModule module3 = ModuleSet2.Modules["mod5"];
            IModule module4 = myModuleSet2.Modules["mod5"];
            IModule module5 = ModuleSet2.Modules["mod3"];
            IModule module6 = myModuleSet2.Modules["mod3"];

            Assert.True(module1.Equals(module2));
            Assert.True(module3.Equals(module4));
            Assert.True(module5.Equals(module6));
        }
Ejemplo n.º 6
0
        public void TestEquality()
        {
            Assert.Equal(Module1, Module1);
            Assert.Equal(Module1, Module2);
            Assert.Equal(Module8, Module8);
            Assert.NotEqual(Module1, Module3);
            Assert.NotEqual(Module1, Module4);
            Assert.NotEqual(Module1, Module5);
            Assert.NotEqual(Module1, Module6);
            Assert.NotEqual(Module1, Module7);
            Assert.Equal(Module1, Module8);

            Assert.False(Module1.Equals(null));
            Assert.False(Module8.Equals(null));

            Assert.True(Module1.Equals(Module1));
            Assert.False(Module1.Equals(Module3));

            Assert.False(Module1.Equals((object)null));
            Assert.False(Module8.Equals((object)null));
            Assert.True(Module1.Equals((object)Module1));
            Assert.False(Module1.Equals((object)Module3));
            Assert.False(Module1.Equals(new object()));

            Assert.Equal(Module1.GetHashCode(), Module2.GetHashCode());
            Assert.NotEqual(Module1.GetHashCode(), Module3.GetHashCode());

            Assert.Equal(Config1, Config1);
            Assert.Equal(Config1, Config3);
            Assert.NotEqual(Config1, Config2);
            Assert.True(Config1.Equals((object)Config1));
            Assert.False(Config1.Equals(null));
        }
Ejemplo n.º 7
0
        public void TestDeserialize()
        {
            string validJson         = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"Settings\":{\"Image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"settings\":{\"image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string validJsonAllLower = "{\"modules\":{\"mod1\":{\"version\":\"version1\",\"type\":\"test\",\"status\":\"running\",\"settings\":{\"image\":\"image1\"},\"restartpolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"version\":\"version1\",\"type\":\"test\",\"status\":\"running\",\"settings\":{\"image\":\"image1\"},\"restartpolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string validJsonAllCap   = "{\"MODULES\":{\"mod1\":{\"NAME\":\"mod1\",\"VERSION\":\"version1\",\"TYPE\":\"test\",\"STATUS\":\"RUNNING\",\"SETTINGS\":{\"IMAGE\":\"image1\"},\"RESTARTPOLICY\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"NAME\":\"mod2\",\"VERSION\":\"version1\",\"TYPE\":\"test\",\"STATUS\":\"RUNNING\",\"SETTINGS\":{\"IMAGE\":\"image1\"},\"RESTARTPOLICY\":\"on-unhealthy\",\"CONFIGURATION\":{\"id\":\"1\"}}}}";

            string noVersionJson     = "{\"Modules\":{\"mod1\":{\"Type\":\"test\",\"Status\":\"Running\",\"Settings\":{\"Image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Type\":\"test\",\"Status\":\"Running\",\"settings\":{\"image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string noTypeJson        = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Status\":\"Running\",\"Settings\":{\"Image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Status\":\"Running\",\"settings\":{\"image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string noStatusJson      = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Type\":\"test\",\"Settings\":{\"Image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Type\":\"test\",\"settings\":{\"image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string noConfigJson      = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"Settings\":{\"Image\":\"image1\"},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string noConfigImageJson = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"Settings\":{},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"settings\":{},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";
            string notATestType      = "{\"Modules\":{\"mod1\":{\"Version\":\"version1\",\"Type\":\"not_a_test\",\"Status\":\"Running\",\"Settings\":{},\"RestartPolicy\":\"on-unhealthy\",\"Configuration\":{\"id\":\"1\"}},\"mod2\":{\"Version\":\"version1\",\"Type\":\"test\",\"Status\":\"Running\",\"settings\":{},\"RestartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\"}}}}";

            var serializerInputTable = new Dictionary <string, Type>()
            {
                { "Test", typeof(TestModule) }
            };
            var myModuleSetSerde = new ModuleSetSerde(serializerInputTable);

            ModuleSet myModuleSet1 = myModuleSetSerde.Deserialize(validJson);
            ModuleSet myModuleSet2 = myModuleSetSerde.Deserialize(validJsonAllLower);
            ModuleSet myModuleSet3 = myModuleSetSerde.Deserialize(validJsonAllCap);

            IModule myModule1 = myModuleSet1.Modules["mod1"];
            IModule myModule2 = myModuleSet1.Modules["mod2"];
            IModule myModule3 = myModuleSet2.Modules["mod1"];
            IModule myModule4 = myModuleSet2.Modules["mod2"];
            IModule myModule5 = myModuleSet3.Modules["mod1"];
            IModule myModule6 = myModuleSet3.Modules["mod2"];

            Assert.True(Module1.Equals(myModule1));
            Assert.True(Module2.Equals(myModule2));
            Assert.True(Module1.Equals(myModule3));
            Assert.True(Module2.Equals(myModule4));
            Assert.True(Module1.Equals(myModule5));
            Assert.True(Module2.Equals(myModule6));

            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(noVersionJson));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(noStatusJson));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(noTypeJson));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(noConfigJson));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(noConfigImageJson));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(notATestType));
            Assert.Throws <JsonSerializationException>(() => myModuleSetSerde.Deserialize(null));
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            IModule targetModule = typeElement.Module.ContainingProjectModule;

            if (targetModule == null)
            {
                return(false);
            }

            return(sourceModule.Equals(targetModule));
        }
Ejemplo n.º 9
0
        public void TestSerializeWithNull()
        {
            string  jsonFromDockerModule       = ModuleSerde.Instance.Serialize(Module1);
            IModule myModule                   = ModuleSerde.Instance.Deserialize <DockerRuntimeModule>(jsonFromDockerModule);
            IModule moduleFromSerializedModule = ModuleSerde.Instance.Deserialize <DockerRuntimeModule>(SerializedModule1);

            myModule.Name = "mod1";
            moduleFromSerializedModule.Name = "mod1";

            Assert.True(Module1.Equals(myModule));
            Assert.True(moduleFromSerializedModule.Equals(Module1));
        }