Пример #1
0
        public void TestDiffDeserialize()
        {
            //"mod1", "version1", "type1", ModuleStatus.Running, Config1
            //Config1 = new TestConfig("image1");
            //arrange
            Diff   nonEmptyUpdated            = Diff.Create(Module1);
            string nonEmptyUpdatedJson        = "{\"modules\":{\"mod1\":{\"version\":\"version1\",\"type\":\"test\",\"status\":\"running\",\"settings\":{\"image\":\"image1\"},\"restartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\",\"version\":\"2\"}}},\"$version\":127}";
            string nonEmptyRemovedJson        = "{\"modules\":{\"module2\": null },\"$version\":127}";
            string nonSupportedTypeModuleJson = "{\"modules\":{\"mod1\":{\"version\":\"version1\",\"type\":\"unknown\",\"status\":\"running\",\"settings\":{\"image\":\"image1\"},\"restartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\",\"version\":\"2\"}}},\"$version\":127}";
            string noTypeDiffJson             = "{\"modules\":{\"mod1\":{\"version\":\"version1\",\"status\":\"running\",\"settings\":{\"image\":\"image1\"},\"restartPolicy\":\"on-unhealthy\",\"configuration\":{\"id\":\"1\",\"version\":\"2\"}}},\"$version\":127}";

            var nonEmptyRemoved = new Diff(ImmutableList <IModule> .Empty, new List <string> {
                "module2"
            });

            var serializerInputTable = new Dictionary <string, Type>()
            {
                { "test", typeof(TestModule) }
            };
            var diffSerde = new DiffSerde(serializerInputTable);

            //act
            Diff nonEmptyUpdatedDeserialized = diffSerde.Deserialize(nonEmptyUpdatedJson);
            Diff nonEmptyRemovedDeserialized = diffSerde.Deserialize(nonEmptyRemovedJson);

            //assert
            Assert.Throws <JsonSerializationException>(() => diffSerde.Deserialize(nonSupportedTypeModuleJson));
            Assert.Throws <NotSupportedException>(() => diffSerde.Deserialize <Diff>(nonEmptyUpdatedJson));
            Assert.Throws <JsonSerializationException>(() => diffSerde.Deserialize(noTypeDiffJson));
            Assert.True(nonEmptyUpdatedDeserialized.Equals(nonEmptyUpdated));
            Assert.True(nonEmptyRemovedDeserialized.Equals(nonEmptyRemoved));
        }
Пример #2
0
        public void TestEquals()
        {
            Diff nonEmptyUpdated = Diff.Create(Module1);
            var  nonEmptyRemoved = new Diff(ImmutableList <IModule> .Empty, new List <string> {
                "module2"
            });
            Diff   alsoNonEmptyDiff = nonEmptyUpdated;
            object nonEmptyUpdatedObjectSameReference = nonEmptyUpdated;

            Assert.False(nonEmptyUpdated.Equals(null));
            Assert.True(nonEmptyUpdated.Equals(alsoNonEmptyDiff));
            Assert.False(nonEmptyUpdated.Equals(new object()));
            Assert.True(nonEmptyUpdated.Equals(nonEmptyUpdatedObjectSameReference));

            Assert.False(Diff.Empty.Equals(nonEmptyUpdated));
            Assert.False(Diff.Empty.Equals(nonEmptyRemoved));
            Assert.False(nonEmptyUpdated.Equals(nonEmptyRemoved));

            Assert.Equal(Module1, Module1A);
            Assert.True(nonEmptyUpdated.Equals(Diff.Create(Module1A)));
        }