public async Task SynchronizeTwoWay_CacheIsClearedAfterFirstRun_FindsMatchingEntitiesInSecondRun()
        {
            var options = TestComponentContainer.GetOptions("IntegrationTest/Events/Sogo");

            options.SynchronizationMode = SynchronizationMode.MergeInBothDirections;

            var synchronizer = await CreateSynchronizer(options);

            await synchronizer.ClearEventRepositoriesAndCache();

            await synchronizer.CreateEventInOutlook("first", DateTime.Now.AddDays(11), DateTime.Now.AddDays(20));

            await synchronizer.CreateEventInOutlook("second", DateTime.Now.AddDays(-11), DateTime.Now.AddDays(-9));

            await synchronizer.CreateEventInOutlook("third", DateTime.Now.AddDays(9), DateTime.Now.AddDays(11));

            await synchronizer.SynchronizeAndAssertNoErrors();

            var relations = synchronizer.Components.EntityRelationDataAccess.LoadEntityRelationData().Select(r => new { r.AtypeId, r.BtypeId }).ToArray();

            Assert.That(relations.Length, Is.EqualTo(3));

            synchronizer.ClearCache();

            await synchronizer.SynchronizeAndAssertNoErrors();

            CollectionAssert.AreEquivalent(
                relations,
                synchronizer.Components.EntityRelationDataAccess.LoadEntityRelationData().Select(r => new { r.AtypeId, r.BtypeId })
                );
        }
Example #2
0
        public void ComponentValues_AreValid()
        {
            var container = TestComponentContainer.CreateInstance();
            var component = new ComplexComponent
            {
                Integer = 1,
                Float   = 123.456f,
                String  = "test",
                Nested  = new ComponentA
                {
                    Integer = 42
                },
                ListInteger = new List <int> {
                    1, 1, 2, 3, 5, 8, 13
                }
            };

            container.SetComponent(component);

            var value = container.GetComponent <ComplexComponent>();

            Assert.That(value.Integer, Is.EqualTo(1));
            Assert.That(value.Float, Is.EqualTo(123.456f));
            Assert.That(value.String, Is.EqualTo("test"));
            Assert.That(value.Nested.Integer, Is.EqualTo(42));
            Assert.That(value.ListInteger, Is.EquivalentTo(new List <int> {
                1, 1, 2, 3, 5, 8, 13
            }));
        }
Example #3
0
        public void AddDependency_CannotAddSelfDependency()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.That(container.AddDependency(container), Is.False);
            Assert.That(container.Dependencies.Count, Is.Zero);
        }
        public void DeserializeInvalidJson_ShouldNotThrowException()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            LogAssert.Expect(LogType.Error, "Input json was invalid. ExpectedType=[Value] ActualType=[EndObject] ActualChar=['}'] at Line=[1] at Character=[47]");
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
Example #5
0
        public void RemoveComponent()
        {
            var container = TestComponentContainer.CreateInstance();

            container.SetComponent(new ComponentA());
            container.SetComponent(new ComponentB());
            container.SetComponent(new ComplexComponent());

            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.HasComponent <ComponentB>(), Is.True);
            Assert.That(container.HasComponent <ComplexComponent>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(3));

            Assert.That(container.RemoveComponent <ComplexComponent>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(2));

            Assert.That(container.RemoveComponent <DerivedClass>(), Is.False);
            Assert.That(container.Components.Count, Is.EqualTo(2));

            Assert.That(container.RemoveComponent <ITestInterface>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(0));

            Assert.Throws <ArgumentNullException>(() => container.RemoveComponent(null));
            Assert.Throws <InvalidOperationException>(() => container.RemoveComponent(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => container.RemoveComponent(typeof(InvalidComponent)));
        }
Example #6
0
        public void DeserializeInvalidJson_ShouldNotThrowException()
        {
            var container = TestComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestComponentContainer).FullName}':\nInput json was invalid. ExpectedType=[Value] ActualType=[EndObject] ActualChar=['}}'] at Line=[1] at Character=[47]");
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
Example #7
0
        public void GetComponents_WithType()
        {
            var containerA       = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));
            var containerB       = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentB()));
            var complexContainer = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComplexComponent()));

            containerA.AddDependency(containerB);
            containerB.AddDependency(complexContainer);

            Assert.That(containerA.GetComponents <ComponentA>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentA) }));
            Assert.That(containerA.GetComponents <ComponentB>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentB) }));
            Assert.That(containerA.GetComponents <ComplexComponent>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComplexComponent) }));

            Assert.That(containerB.GetComponents <ComponentA>(), Is.Empty);
            Assert.That(containerB.GetComponents <ComponentB>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentB) }));
            Assert.That(containerB.GetComponents <ComplexComponent>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComplexComponent) }));

            Assert.That(complexContainer.GetComponents <ComponentA>(), Is.Empty);
            Assert.That(complexContainer.GetComponents <ComponentB>(), Is.Empty);
            Assert.That(complexContainer.GetComponents <ComplexComponent>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComplexComponent) }));

            Assert.That(containerA.GetComponents <ITestInterface>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentA), typeof(ComponentB) }));
            Assert.That(containerB.GetComponents <ITestInterface>().Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentB) }));
            Assert.That(complexContainer.GetComponents <ITestInterface>(), Is.Empty);
        }
Example #8
0
        public void ComponentOverrides_FromMultipleDependencies()
        {
            var containerA = TestComponentContainer.CreateInstance();

            containerA.SetComponent(new ComponentA {
                Integer = 1
            });

            var containerB = TestComponentContainer.CreateInstance();

            containerB.AddDependency(containerA);

            var componentA = containerB.GetComponent <ComponentA>();

            componentA.Float = 123.456f;
            containerB.SetComponent(componentA);

            var containerC = TestComponentContainer.CreateInstance();

            containerC.AddDependency(containerB);

            componentA        = containerC.GetComponent <ComponentA>();
            componentA.String = "test";
            containerC.SetComponent(componentA);

            var containerD = TestComponentContainer.CreateInstance();

            containerD.AddDependency(containerC);

            var value = containerD.GetComponent <ComponentA>();

            Assert.That(value.Integer, Is.EqualTo(1));
            Assert.That(value.Float, Is.EqualTo(123.456f));
            Assert.That(value.String, Is.EqualTo("test"));
        }
        public async Task Synchronize_ServerEventContainsOrganizer_IsSyncedToOutlookAndBackToServer()
        {
            var options = TestComponentContainer.GetOptions("IntegrationTest/Events/Sogo");

            options.SynchronizationMode = SynchronizationMode.MergeInBothDirections;

            var synchronizer = await CreateSynchronizer(options);

            await synchronizer.ClearEventRepositoriesAndCache();


            await synchronizer.CreateEventOnServer("bla", DateTime.Now.AddDays(11), DateTime.Now.AddDays(20), e => e.Organizer = new Organizer("*****@*****.**"));

            await synchronizer.SynchronizeAndAssertNoErrors();

            using (var outlookEvent = (await synchronizer.Outlook.GetAllEntities()).Single().Entity)
            {
                Assert.That(outlookEvent.Inner.Organizer, Is.EqualTo("*****@*****.**"));
                outlookEvent.Inner.Subject = "TheNewSubject";
                outlookEvent.Inner.Save();
            }

            await synchronizer.SynchronizeAndAssertNoErrors();

            var serverEvent = (await synchronizer.Server.GetAllEntities()).Single().Entity;

            Assert.That(serverEvent.Events[0].Summary, Is.EqualTo("TheNewSubject"));
            Assert.That(serverEvent.Events[0].Organizer.Value.ToString(), Is.EqualTo("mailto:[email protected]"));
        }
        public void DeserializeInvalidComponent_ShouldNotResetEntireBuildSettings()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            LogAssert.Expect(LogType.Error, new Regex("Encountered problems while deserializing in memory container of type TestComponentContainer:.*"));
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}, {\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
Example #11
0
        public void AddingDestoyedDependency_Throws()
        {
            var settings          = TestComponentContainer.CreateInstance();
            var missingDependency = TestComponentContainer.CreateInstance();

            UnityEngine.Object.DestroyImmediate(missingDependency);
            Assert.Throws <ArgumentNullException>(() => settings.AddDependency(missingDependency));
        }
Example #12
0
        public void DeserializeInvalidDependency_ShouldNotResetEntireBuildSettings()
        {
            var container = TestComponentContainer.CreateInstance();

            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [null, \"\", \"bleh\"], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Dependencies.Count, Is.Zero);
        }
Example #13
0
        public void DeserializeInvalidComponent_ShouldNotResetEntireBuildSettings()
        {
            var container = TestComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestComponentContainer).FullName}':\nSystem.InvalidOperationException: PropertyContainer.Construct failed to construct DstType=[{typeof(ITestComponent).FullName}]. Could not resolve type from TypeName=[Some.InvalidComponent.Name, Unknown.Assembly].");
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}, {{\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
        public void DeserializeInvalidDependency_ShouldNotResetEntireBuildSettings()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [null, \"\"], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.GetDependencies().Count, Is.EqualTo(2));
        }
Example #15
0
        public void CannotSet_AbstractType()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.Throws <InvalidOperationException>(() =>
            {
                container.SetComponent(typeof(AbstractClass), new DerivedClass());
            });
        }
Example #16
0
        public void CannotSet_InterfaceType()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.Throws <InvalidOperationException>(() =>
            {
                container.SetComponent(typeof(ITestInterface), new ComponentA());
            });
        }
Example #17
0
        public void CannotSet_NullType()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.Throws <ArgumentNullException>(() =>
            {
                container.SetComponent(null, new ComponentA());
            });
        }
Example #18
0
        protected async Task InitializeSynchronizer(int?chunkSize)
        {
            var options = TestComponentContainer.GetOptions(ProfileName);

            options.ChunkSize = chunkSize ?? 0;
            options.IsChunkedSynchronizationEnabled = chunkSize.HasValue;
            Synchronizer = CreateSynchronizer(options);
            await Synchronizer.Initialize();
        }
        public async Task SynchronizeToServer_AllDayEventsWithTimeRangeFilter_DoesntDuplicateOrDeleteBoundaryEvents(string profileName)
        {
            var options = TestComponentContainer.GetOptions(profileName);

            options.SynchronizationMode = SynchronizationMode.ReplicateOutlookIntoServer;

            var synchronizer = await CreateSynchronizer(options);

            await synchronizer.ClearEventRepositoriesAndCache();

            await synchronizer.CreateEventInOutlook("Event -5", DateTime.Today.AddDays(-5), DateTime.Now.AddDays(-5), true);

            await synchronizer.CreateEventInOutlook("Event -4", DateTime.Today.AddDays(-4), DateTime.Now.AddDays(-4), true);

            await synchronizer.CreateEventInOutlook("Event -3", DateTime.Today.AddDays(-3), DateTime.Now.AddDays(-3), true);

            await synchronizer.CreateEventInOutlook("Event -2", DateTime.Today.AddDays(-2), DateTime.Now.AddDays(-2), true);

            await synchronizer.CreateEventInOutlook("Event -1", DateTime.Today.AddDays(-1), DateTime.Now.AddDays(-1), true);

            await synchronizer.CreateEventInOutlook("Event 0", DateTime.Today.AddDays(0), DateTime.Now.AddDays(0), true);

            await synchronizer.CreateEventInOutlook("Event 1", DateTime.Today.AddDays(1), DateTime.Now.AddDays(1), true);

            await synchronizer.CreateEventInOutlook("Event 2", DateTime.Today.AddDays(2), DateTime.Now.AddDays(2), true);

            await synchronizer.CreateEventInOutlook("Event 3", DateTime.Today.AddDays(3), DateTime.Now.AddDays(3), true);

            await synchronizer.CreateEventInOutlook("Event 4", DateTime.Today.AddDays(4), DateTime.Now.AddDays(4), true);

            await synchronizer.CreateEventInOutlook("Event 5", DateTime.Today.AddDays(5), DateTime.Now.AddDays(5), true);

            await synchronizer.SynchronizeAndCheck(
                unchangedA : 0, addedA : 11, changedA : 0, deletedA : 0,
                unchangedB : 0, addedB : 0, changedB : 0, deletedB : 0,
                createA : 0, updateA : 0, deleteA : 0,
                createB : 11, updateB : 0, deleteB : 0);

            synchronizer.ClearCache();

            for (int rangeInDays = 1; rangeInDays <= 5; rangeInDays++)
            {
                options.DaysToSynchronizeInTheFuture   = rangeInDays;
                options.DaysToSynchronizeInThePast     = rangeInDays;
                options.IgnoreSynchronizationTimeRange = false;
                synchronizer = await CreateSynchronizer(options);

                var expectedNumberOfEvents = rangeInDays * 2 + 2 - (rangeInDays == 5 ? 1 : 0);

                await synchronizer.SynchronizeAndCheck(
                    unchangedA : expectedNumberOfEvents, addedA : 0, changedA : 0, deletedA : 0,
                    unchangedB : expectedNumberOfEvents, addedB : 0, changedB : 0, deletedB : 0,
                    createA : 0, updateA : 0, deleteA : 0,
                    createB : 0, updateB : 0, deleteB : 0);
            }
        }
Example #20
0
        public void GetComponent()
        {
            var container = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));

            Assert.That(container.GetComponent <ComponentA>(), Is.Not.Null);
            Assert.Throws <InvalidOperationException>(() => container.GetComponent <ComponentB>());
            Assert.Throws <ArgumentNullException>(() => container.GetComponent(null));
            Assert.Throws <InvalidOperationException>(() => container.GetComponent(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => container.GetComponent(typeof(InvalidComponent)));
        }
Example #21
0
        public void AddDependency()
        {
            var containerA = TestComponentContainer.CreateInstance();
            var containerB = TestComponentContainer.CreateInstance();

            Assert.That(containerA.AddDependency(containerB), Is.True);
            Assert.That(containerA.AddDependency(containerB), Is.False);
            Assert.That(containerA.Dependencies, Is.EqualTo(new[] { containerB }));
            Assert.Throws <ArgumentNullException>(() => containerA.AddDependency(null));
        }
Example #22
0
        public void SetComponent()
        {
            var container = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));

            Assert.That(container.Components.Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(ComponentA) }));
            Assert.Throws <ArgumentNullException>(() => container.SetComponent(null, default));
            Assert.Throws <InvalidOperationException>(() => container.SetComponent(typeof(object), default));
            Assert.Throws <InvalidOperationException>(() => container.SetComponent(typeof(InvalidComponent), default));
            Assert.Throws <InvalidOperationException>(() => container.SetComponent(typeof(ITestInterface), default));
        }
Example #23
0
        public void TryGetComponent()
        {
            var container = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));

            Assert.That(container.TryGetComponent <ComponentA>(out var _), Is.True);
            Assert.That(container.TryGetComponent <ComponentB>(out var _), Is.False);
            Assert.That(container.TryGetComponent(null, out var _), Is.False);
            Assert.That(container.TryGetComponent(typeof(object), out var _), Is.False);
            Assert.That(container.TryGetComponent(typeof(InvalidComponent), out var _), Is.False);
        }
Example #24
0
        public void RemoveDependency()
        {
            var containerA = TestComponentContainer.CreateInstance();
            var containerB = TestComponentContainer.CreateInstance();

            containerA.AddDependency(containerB);

            Assert.That(containerA.RemoveDependency(containerB), Is.True);
            Assert.That(containerA.RemoveDependency(containerB), Is.False);
            Assert.That(containerB.RemoveDependency(containerA), Is.False);
            Assert.Throws <ArgumentNullException>(() => containerA.RemoveDependency(null));
        }
        public void DeserializeMultipleTimes_ShouldNotAppendData()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            Assert.That(container.HasComponent <ComponentA>(), Is.False);
            Assert.That(container.Components.Count, Is.Zero);
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
        }
Example #26
0
        public void DeserializeMultipleTimes_ShouldNotAppendData()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.That(container.HasComponent <ComponentA>(), Is.False);
            Assert.That(container.Components.Count, Is.Zero);
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
        }
Example #27
0
        public void GetDependencies()
        {
            var containerA = TestComponentContainer.CreateInstance();
            var containerB = TestComponentContainer.CreateInstance();
            var containerC = TestComponentContainer.CreateInstance();

            containerA.AddDependency(containerB);
            containerB.AddDependency(containerC);

            Assert.That(containerA.GetDependencies(), Is.EqualTo(new[] { containerB, containerC }));
            Assert.That(containerB.GetDependencies(), Is.EqualTo(new[] { containerC }));
            Assert.That(containerC.GetDependencies(), Is.Empty);
        }
Example #28
0
        public void IsComponentOverridden()
        {
            var containerA = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));
            var containerB = TestComponentContainer.CreateInstance(c => c.SetComponent(new ComponentA()));

            containerA.AddDependency(containerB);

            Assert.That(containerA.IsComponentOverridden <ComponentA>(), Is.True);
            Assert.That(containerB.IsComponentOverridden <ComponentA>(), Is.False);

            Assert.Throws <ArgumentNullException>(() => containerA.IsComponentOverridden(null));
            Assert.Throws <InvalidOperationException>(() => containerA.IsComponentOverridden(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => containerA.IsComponentOverridden(typeof(InvalidComponent)));
        }
Example #29
0
        public void ClearDependencies()
        {
            var containerA = TestComponentContainer.CreateInstance();
            var containerB = TestComponentContainer.CreateInstance();
            var containerC = TestComponentContainer.CreateInstance();

            containerA.AddDependency(containerB);
            containerA.AddDependency(containerC);

            Assert.That(containerA.Dependencies.Count, Is.EqualTo(2));
            Assert.DoesNotThrow(() => containerA.ClearDependencies());
            Assert.That(containerA.Dependencies, Is.Empty);
            Assert.DoesNotThrow(() => containerA.ClearDependencies());
            Assert.That(containerA.Dependencies, Is.Empty);
        }
Example #30
0
        public void CanQuery_InterfaceType()
        {
            var container = TestComponentContainer.CreateInstance();

            container.SetComponent(new ComponentA {
                Float = 123.456f, Integer = 42, String = "foo"
            });

            Assert.That(container.HasComponent(typeof(ITestInterface)));
            Assert.That(container.TryGetComponent(typeof(ITestInterface), out var value), Is.True);
            Assert.That(value, Is.EqualTo(new ComponentA {
                Float = 123.456f, Integer = 42, String = "foo"
            }));
            Assert.That(container.RemoveComponent(typeof(ITestInterface)), Is.True);
        }