Пример #1
0
        public void Test()
        {
            const string prefix = "Whatever";
            const string foo    = "My String foo";
            const string bar    = "My String bar";
            const string baz    = "My baz String";

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Foo)), foo },
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Level2), nameof(MultiLevel2.Bar)), bar },
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Level2), nameof(MultiLevel2.Level3), nameof(MultiLevel3.Baz)), baz },
            }));

            var setting = settingsLoader.Create <MultiLevel1>(prefix);

            var expected = new MultiLevel1()
            {
                Foo    = foo,
                Level2 = new MultiLevel2()
                {
                    Bar    = bar,
                    Level3 = new MultiLevel3()
                    {
                        Baz = baz
                    }
                }
            };

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting, Is.DeepEqualTo(expected));
        }
Пример #2
0
        public async Task MeetingTypeControllerRef()
        {
            var data = new MeetingTypeApiDataHandler();
            var list = new List <ResultOwned> {
                MeetingTypeData.GetFirstOwned()
            };
            var filter = new MeetingTypeFilter {
                TenantRestrict = true
            };

            data.Result.Setup(m => m.Execute(It.IsAny <MeetingTypeRefByFilter>())).Returns(list);

            var controller = new MeetingTypeController(data, Logic)
            {
                CurrentUser = AdminUser
            };
            var result = await controller.Ref(filter) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as PagedResult <IEnumerable <ResultOwned> >;

            check.Data.Should().NotBeNull();
            check.Data.Count().Should().Be(list.Count);

            Assert.That(check.Data, Is.DeepEqualTo(list));

            data.HasExecuted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <MeetingTypeRefByFilter>()), Times.Once());
        }
Пример #3
0
        public async Task UserControllerFilter()
        {
            var data = new FakeApiDataResultHandler <Tenant, TenantDisplay>();
            var list = new List <TenantDisplay> {
                TenantData.GetFirstDisplay()
            };
            var filter = new TenantFilter {
                TenantRestrict = true
            };

            data.Result.Setup(m => m.Execute(It.IsAny <TenantDisplayByFilter>())).Returns(list);

            var controller = new TenantController(data, Logic)
            {
                CurrentUser = SuperUser
            };
            var result = await controller.Filter(filter) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as PagedResult <IEnumerable <TenantDisplay> >;

            check.Should().NotBeNull();
            check.Data.Count().Should().Be(list.Count);

            Assert.That(check.Data, Is.DeepEqualTo(list));

            data.HasExecuted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <TenantDisplayByFilter>()), Times.Once());
        }
        public void GetInvoiceObjct_MoreExpressive_Test()
        {
            // Arrange
            var expected = new List <InvoiceItem>
            {
                new InvoiceItem(1, "IPad", 20.00d),
                new InvoiceItem(2, "Stand for IPad", 15.00d),
                new InvoiceItem(3, "LapTop Asus", 505.00d)
            }.ToList();

            // Act
            Invoice invoice        = new InvoiceBuilder().WithInvoiceLines();
            var     resultTypeTest = invoice.GetInvoiceItems();
            var     resultValues   = resultTypeTest.InvoiceList.ToList();

            // Assert


            Assert.IsInstanceOf <InvoiceLines>(resultTypeTest);
            Assert.That(expected, DeepObj.DeepEqualTo(resultValues));
            //AssertHelper.HasEqualFieldValues(expected, resultValues);

            //Assert.IsInstanceOf<List<InvoiceItem>>(lines);

            //Assert.That(expected, Is.EqualTo(lines));

            //Assert.That("Hello", Is.TypeOf(typeof(string)));
            //Assert.That("Hello", Is.Not.TypeOf(typeof(int)));
            //Assert.That(invoice.lines, Is.EqualTo(expected));
            //Assert.That(new[] { 1.05, 2.05, 3.05 }, Is.EquivalentTo(new[] { 3.0, 2.0, 1.0 }));
        }
Пример #5
0
        public void ListLoadTest()
        {
            var settings = SettingsLoader.Create <ListSettings>();

            // List
            Assert.That(settings.MySimpleListProperty, Is.DeepEqualTo(
                            new List <string>
            {
                "Foo 1",
                "Foo 2"
            }));
            Assert.That(settings.MyListProperty, Is.DeepEqualTo(
                            new List <Nested>
            {
                new Nested {
                    Foo = "Foo 1", Bar = 421
                },
                new Nested {
                    Foo = "Foo 2", Bar = 422
                },
            }));
            Assert.That(settings.LostNumbersList, Is.EqualTo(
                            new[]
            {
                4, 8, 15, 16, 23, 42
            }));
        }
Пример #6
0
        public void ShouldReadCreatedWadFile()
        {
            var fileInfo = new FileInfo(Path.GetTempFileName());

            try
            {
                var map = DemoMap.Create();

                var wadWriter = new WadWriter();
                wadWriter.Append("MAP01", map);
                wadWriter.SaveTo(fileInfo.FullName);

                using (var wadReader = WadReader.Read(fileInfo.FullName))
                {
                    Assert.That(wadReader.Directory.Length, Is.EqualTo(3), "Did not return correct count.");
                    Assert.That(
                        wadReader.Directory.Select(l => l.Name).ToArray(),
                        Is.EquivalentTo(new[]
                                        { new LumpName("MAP01"), new LumpName("TEXTMAP"), new LumpName("ENDMAP"), }),
                        "Did not return correct lump names.");

                    var roundTripped = MapData.LoadFrom(wadReader.GetTextmapStream("MAP01"));

                    Assert.That(roundTripped, Is.DeepEqualTo(map));
                }
            }
            finally
            {
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
            }
        }
Пример #7
0
        public void DictionaryLoadTest()
        {
            var settings = SettingsLoader.Create <DictionarySettings>();

            // Various Dictionarys
            Assert.That(settings.MySimpleDictionaryProperty, Is.EquivalentTo(
                            new Dictionary <string, string>
            {
                { "Foo", "oof" },
                { "Bar", "rab" }
            }));
            Assert.That(settings.MyNumericDictionaryProperty, Is.EquivalentTo(
                            new Dictionary <string, byte>
            {
                { "Foo", 14 },
                { "Bar", 42 }
            }));
            Assert.That(settings.MyDictionaryProperty, Is.DeepEqualTo(
                            new Dictionary <string, Nested>
            {
                { "Key1", new Nested {
                      Foo = "oof1", Bar = 421
                  } },
                { "Key2", new Nested {
                      Foo = "oof2", Bar = 422
                  } }
            }).WithComparisonConfig(new ComparisonConfig()
            {
                IgnoreCollectionOrder = true
            }));
        }
Пример #8
0
        public void Test()
        {
            const string @string = "My String foo";
            const string present = "World";
            var          nested  = new Nested {
                Foo = "Foo1", Bar = -15
            };
            var prefix = "Hello";
            var array  = new[] { " Mickey", "Mouse " };

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.String)), @string },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalPresent)), present },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Foo)), nested.Foo },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Bar)), nested.Bar.ToString() },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "1"), array[0] },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "2"), array[1] }
            }));

            var setting = settingsLoader.Create <OptionalSettings>(prefix);

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting.String, Is.EqualTo(@string));
            Assert.That(setting.OptionalMissing, Is.Null);
            Assert.That(setting.OptionalPresent, Is.EqualTo(present));
            Assert.That(setting.OptionalNestedMissing, Is.Null);
            Assert.That(setting.OptionalNestedPresent, Is.DeepEqualTo(nested));
            Assert.That(setting.OptionalArrayMissing, Is.Null);
            Assert.That(setting.OptionalArrayPresent, Is.DeepEqualTo(array));
        }
Пример #9
0
            public void _3_1_1_Has4x4Field_DontHaveAnyPossibility()
            {
                var n        = 4;
                var testable = new _3_1_1();
                var expected = new List <Pos>
                {
                    new Pos {
                        Row = 0, Col = 1
                    },
                    new Pos {
                        Row = 1, Col = 3
                    },
                    new Pos {
                        Row = 2, Col = 0
                    },
                    new Pos {
                        Row = 3, Col = 2
                    }
                };

                var result = testable.Run(n);

                result.Reverse();

                Assert.That(result.Any());
                Assert.That(result, IsDeepEqual.DeepEqualTo(expected));
            }
Пример #10
0
        public void GetNestedFromDatabase()
        {
            var dictionary = SettingsLoader.Create <Nested>();

            Assert.That(dictionary, Is.DeepEqualTo(
                            new Nested
            {
                Bar = 14,
                Foo = "Foo from database"
            }));
        }
Пример #11
0
        public void SerializeDeserialize_ListWithTwoNodes_Success()
        {
            var serializer = GetSerializer();
            var origin     = ContainerOfListNodes.ListRandWithOneNodeThatHasRandNode;

            var serialized   = serializer.Serialize(origin);
            var splitted     = serialized.SelectMany(x => x.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)).ToList();;
            var deserialized = serializer.Deserialize(splitted);

            Assert.That(origin, DeepCompare.DeepEqualTo(deserialized));
        }
Пример #12
0
        public void DirectNumericArrayLoadTest()
        {
            var settings = SettingsLoader.CreateArray <int>("MyNumericArrayProperty");

            // Array
            Assert.That(settings, Is.DeepEqualTo(
                            new int[]
            {
                1, 2, 3, 4
            }));
        }
Пример #13
0
        public void OptionalInlineLoadTest()
        {
            var settings = SettingsLoader.Create <OptionalInlineSettings>();

            // Nested
            Assert.That(settings, Is.DeepEqualTo(
                            new OptionalInlineSettings()
            {
                MyNestedProperty = null,
                Baz = TimeSpan.Parse("01:02:03")
            }));
        }
Пример #14
0
        public void GetKeysTest()
        {
            var dictionary = SettingsLoader.CreateDictionary <string, string>();

            Assert.That(dictionary, Is.DeepEqualTo(
                            new Dictionary <string, string>
            {
                { "Bar", "14" },
                { "Baz", "hello world" },
                { "Foo", "Foo from database" },
            }));
        }
Пример #15
0
        public void SettingReferenceLoadTest()
        {
            var settings = SettingsLoader.Create <ReferenceSettings>("SettingReference");

            // Example of loading settings with references to other settings
            Assert.That(settings, Is.DeepEqualTo(
                            new ReferenceSettings()
            {
                MyUrl    = new Uri("http://foo.bar"),
                PageUrl  = new Uri(new Uri("http://foo.bar"), "/home/index.aspx"),
                LoginUrl = new Uri(new Uri("http://foo.bar"), "/login.aspx"),
            }));
        }
Пример #16
0
        public async Task NoteByRefIdDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var loader = new NotesByRefId {
                Session = session, Id = UserData.FirstId
            };
            await loader.Execute();

            loader.Result.Should().NotBeNull();
            loader.Result.Id.Should().Be(NoteData.FirstId);
            Assert.That(loader.Result, Is.DeepEqualTo(NoteData.GetFirst()));
        }
Пример #17
0
        public async Task NotifyTemplateByNameDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var loader = new NotifyTemplateByName {
                Session = session, Name = "welcomeuser"
            };
            await loader.Execute();

            loader.Result.Should().NotBeNull();
            loader.Result.Id.Should().Be(NotifyTemplateData.FirstId);
            Assert.That(loader.Result, Is.DeepEqualTo(NotifyTemplateData.GetFirst()));
        }
Пример #18
0
        public async Task TenantByEntryKeyDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var loader = new TenantByEntryKey {
                Session = session, EntryKey = "first"
            };
            await loader.Execute();

            loader.Result.Should().NotBeNull();
            loader.Result.Id.Should().Be(TenantData.FirstId);
            Assert.That(loader.Result, Is.DeepEqualTo(TenantData.GetFirst()));
        }
Пример #19
0
        public async Task VisibleDisplayByIdDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var query = new VisibleDisplayById {
                Session = session, Id = VisibleData.FirstId
            };
            await query.Execute();

            query.Result.Should().NotBeNull();
            query.Result.Id.Should().Be(VisibleData.FirstId);
            Assert.That(query.Result, Is.DeepEqualTo(VisibleData.GetFirstDisplay()));
        }
Пример #20
0
        public void SettingAttributesWithTypeConverterLoadTest()
        {
            var settings = SettingsLoader.Create <PathTypeConverterSettings>("TypeConverter");

            //Simple
            // Array
            Assert.That(settings, Is.DeepEqualTo(
                            new PathTypeConverterSettings()
            {
                Upload   = @"C:\Foo\Bar\Upload\",
                Download = @"E:\Download\",
                Sub      = @"C:\Foo\Bar\Upload\Sub\",
            }));
        }
Пример #21
0
        public async Task LoadersDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var loader = new Loaders <Tenant> {
                Session = session, Ids = new List <string> {
                    TenantData.FirstId
                }
            };
            await loader.Execute();

            loader.Result.Should().NotBeNull();
            loader.Result.First().Id.Should().Be(TenantData.FirstId);
            Assert.That(loader.Result.First(), Is.DeepEqualTo(TenantData.GetFirst()));
        }
Пример #22
0
        public void NestedLoadTest()
        {
            var settings = SettingsLoader.Create <NestedSettings>();

            // Nested
            Assert.That(settings, Is.DeepEqualTo(
                            new NestedSettings
            {
                MyNestedProperty = new Nested()
                {
                    Foo = "Foo string",
                    Bar = 42
                }
            }));
        }
Пример #23
0
        public async Task TenantSaveDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var model = TenantData.GetSecond();

            var persist = new TenantSave {
                Session = session, Model = model
            };
            await persist.Execute();

            persist.Confirm.Should().NotBeNull();
            persist.Confirm.Identity.Should().Be(model.Id);
            persist.Confirm.Success.Should().BeTrue();
            Assert.That(persist.Model, Is.DeepEqualTo(model));
        }
Пример #24
0
        public void InlineLoadTest()
        {
            var settings = SettingsLoader.Create <InlineSettings>();

            // Nested
            Assert.That(settings, Is.DeepEqualTo(
                            new InlineSettings
            {
                MyNestedProperty = new Nested()
                {
                    Foo = "Inline Foo string",
                    Bar = 21
                },
                Baz = TimeSpan.Parse("01:02:03")
            }));
        }
Пример #25
0
        public async Task TenantDisplayByFilterDataTestSearch()
        {
            var filter = new TenantFilter {
                Search = "Org", Take = 10
            };

            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var query = new TenantDisplayByFilter {
                Session = session, Filter = filter, CurrentUser = StandardUser
            };
            await query.Execute();

            query.Result.Should().NotBeNull();
            query.Result.Count().Should().Be(1);
            Assert.That(query.Result.First(), Is.DeepEqualTo(TenantData.GetFirstDisplay()));
        }
Пример #26
0
        public async Task VisibleDisplayByFilterDataTestImage()
        {
            var filter = new VisibleFilter {
                ImageRestrict = true, Take = 10
            };

            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var query = new VisibleDisplayByFilter {
                Session = session, Filter = filter, CurrentUser = StandardUser
            };
            await query.Execute();

            query.Result.Should().NotBeNull();
            query.Result.Count().Should().Be(1);
            Assert.That(query.Result.First(), Is.DeepEqualTo(VisibleData.GetFirstDisplay()));
        }
Пример #27
0
        public async Task MeetingTypeDisplayByIdDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();

            var query = new MeetingTypeDisplayById {
                Session = session, Id = MeetingTypeData.FirstId
            };
            await query.Execute();

            query.Result.Should().NotBeNull();
            query.Result.Id.Should().Be(MeetingTypeData.FirstId);
            Assert.That(query.Result, Is.DeepEqualTo(MeetingTypeData.GetFirstDisplay(false)));
            query.Result.Searchable.Should().BeNullOrEmpty();
            query.Result.Searchable = new List <string> {
                "something!"
            };
        }
Пример #28
0
        public void DirectDictionaryLoadTest()
        {
            var dict = SettingsLoader.CreateDictionary <string, Nested>(nameof(DictionarySettings.MyDictionaryProperty));

            Assert.That(dict, Is.DeepEqualTo(
                            new Dictionary <string, Nested>
            {
                { "Key1", new Nested {
                      Foo = "oof1", Bar = 421
                  } },
                { "Key2", new Nested {
                      Foo = "oof2", Bar = 422
                  } }
            }).WithComparisonConfig(new ComparisonConfig()
            {
                IgnoreCollectionOrder = true
            }));
        }
        public void ShouldRoundTripDemoMap()
        {
            var map = DemoMap.Create();

            using (var stream = new MemoryStream())
            {
                map.WriteTo(stream);

                stream.Position = 0;

                using (var textReader = new StreamReader(stream, Encoding.ASCII))
                {
                    var sa           = new UdmfSyntaxAnalyzer();
                    var roundTripped = UdmfParser.Parse(sa.Analyze(new UdmfLexer(textReader)));

                    Assert.That(roundTripped, Is.DeepEqualTo(map));
                }
            }
        }
Пример #30
0
        public async Task UserSaveDataTestNoConfig()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();

            var model = UserData.GetSecond();

            model.ConfigId = string.Empty;

            var persist = new UserSave {
                Session = session, Model = model
            };
            await persist.Execute();

            persist.Confirm.Should().NotBeNull();
            persist.Confirm.Identity.Should().Be(UserData.SecondId);
            persist.Confirm.Success.Should().BeTrue();
            Assert.That(persist.Model, Is.DeepEqualTo(model));
        }