Exemplo n.º 1
0
        public async Task PaginateAsyncTest()
        {
            var collections = new List <RandomDataCollection>();

            for (var i = 0; i < 12; i++)
            {
                var collection = await GenerateRandomDataItems(6, true);

                collections.Add(collection);
            }

            var firstResult = await RandomDataService.PaginateAsync(
                new Paginate <RandomDataCollection>
            {
                Limit = 4
            });

            Assert.IsNotNull(firstResult.Next);
            Assert.IsNull(firstResult.Previous);

            var secondResult = await RandomDataService.PaginateAsync(firstResult.Next);

            Assert.IsNotNull(secondResult.Next);
            Assert.IsNotNull(secondResult.Previous);

            var thirdResult = await RandomDataService.PaginateAsync(secondResult.Next);

            Assert.IsNotNull(thirdResult.Previous);
        }
Exemplo n.º 2
0
        public static void ClassSetup(TestContext testContext)
        {
            Client   = new MongoClient("mongodb://127.0.0.1:27017");
            Database = Client.GetDatabase("libraryapi-test");
            var randomDataCollection = new MongoCollection <RandomDataCollection>(Database);

            RandomDataService = new RandomDataService(randomDataCollection);
        }
Exemplo n.º 3
0
        public async Task DeleteAsyncTest()
        {
            var collection = await GenerateRandomDataItems(6, true);

            var result = await RandomDataService.DeleteAsync(collection);

            Assert.IsTrue(result);
        }
Exemplo n.º 4
0
        public async Task RetrieveTest()
        {
            var rd = await GenerateRandomDataItems(6, true);

            var retrievedRd = await RandomDataService.RetrieveAsync(r => r.Id, rd.Id);

            Assert.AreEqual(rd.Id, retrievedRd.Id);
        }
Exemplo n.º 5
0
        public void RandomNumberShouldEqualIfMinAndMaxAreSame()
        {
            IRandomDataService randomDataService = new RandomDataService();

            int val          = 7;
            int randomNumber = randomDataService.RandomNumber(val, val);

            Assert.Equal(val, randomNumber);
        }
Exemplo n.º 6
0
        public async Task UpdateAsyncTest()
        {
            var rd = await GenerateRandomDataItems(6, true);

            rd.Group += "-Test";
            var result = await RandomDataService.UpdateAsync(rd);

            Assert.IsTrue(result.Group.EndsWith("-Test"));
        }
Exemplo n.º 7
0
        public void RandomNumberShouldBeWithinLimits()
        {
            IRandomDataService randomDataService = new RandomDataService();

            int min          = 0;
            int max          = 5;
            int randomNumber = randomDataService.RandomNumber(min, max);

            Assert.InRange(randomNumber, min, max);
        }
Exemplo n.º 8
0
        public async Task DeleteManyAsyncTest()
        {
            var collections = new List <RandomDataCollection>();

            for (var i = 0; i < 3; i++)
            {
                var collection = await GenerateRandomDataItems(6, true);

                collections.Add(collection);
            }

            var result = await RandomDataService.DeleteManyAsync(collections);

            Assert.IsTrue(result);
        }
Exemplo n.º 9
0
        public async Task CreateManyTest()
        {
            var collections = new List <RandomDataCollection>();
            var rnd         = new Random();

            for (var i = 0; i < 3; i++)
            {
                collections.Add(
                    await GenerateRandomDataItems(
                        rnd.Next(0, 9),
                        false));
            }

            var result = await RandomDataService.CreateManyAsync(collections);

            Assert.AreEqual(result.TotalCount, collections.Count);
        }
Exemplo n.º 10
0
        public async Task GetRandomDataItemAsyncTest()
        {
            var group       = "Address";
            var collections = await GenerateRandomDataItems(6, true);

            var firstRndData = await RandomDataService.GetRandomDataItemAsync(group);

            var secondRndData = await RandomDataService.GetRandomDataItemAsync(group);

            var thirdRndData = await RandomDataService.GetRandomDataItemAsync(group);

            Assert.AreNotEqual(
                firstRndData.Id,
                secondRndData.Id,
                thirdRndData.Id);

            Assert.IsTrue(
                (new[] { firstRndData, secondRndData, thirdRndData })
                .All(i => i.UsedRecently == true));
        }
Exemplo n.º 11
0
        public async Task UpdateManyAsyncTest()
        {
            var collections = new List <RandomDataCollection>();

            for (var i = 0; i < 3; i++)
            {
                var collection = await GenerateRandomDataItems(6, true);

                collections.Add(collection);
            }

            foreach (var collection in collections)
            {
                collection.Group += "-Test";
            }

            var result = await RandomDataService.UpdateManyAsync(collections);

            Assert.AreEqual(result.TotalCount, collections.Count);
        }
Exemplo n.º 12
0
        private async Task <RandomDataCollection> GenerateRandomDataItems(
            int number,
            bool save)
        {
            var collection = new RandomDataCollection
            {
                Group = "Address"
            };

            for (var i = 0; i < number; i++)
            {
                var isOf2 = i % 2 == 0;
                var isOf3 = i % 3 == 0;

                var randomData = new RandomDataItem
                {
                    UsedRecently = false,
                    Data         = new Address
                    {
                        Address1      = isOf2 ? "Make Believe Ln." : "Other address",
                        Address2      = isOf3 ? "Suite B" : null,
                        Country       = "United States",
                        FirstName     = isOf2 ? "Tim" : "Bob",
                        LastName      = isOf3 ? "Jones" : "Sparrow",
                        StateProvince = "Wisconsin",
                        ZipCode       = "53186"
                    }
                };

                collection.Items.Add(randomData);
            }

            if (save)
            {
                await RandomDataService.CreateAsync(collection);
            }

            return(collection);
        }
Exemplo n.º 13
0
        public void RandomNumberShouldThrowIfMaxIsSmallerThanMin()
        {
            IRandomDataService randomDataService = new RandomDataService();

            Assert.Throws <ArgumentOutOfRangeException>("max", () => randomDataService.RandomNumber(max: -1));
        }
Exemplo n.º 14
0
        public void RandomDelayShouldThrowIfMaxIsSmallerThanMin()
        {
            IRandomDataService randomDataService = new RandomDataService();

            Assert.ThrowsAsync <ArgumentOutOfRangeException>("maxSeconds", () => randomDataService.RandomDelay(1, 0));
        }
Exemplo n.º 15
0
        public void RandomDelayShouldThrowIfMinIsNegative()
        {
            IRandomDataService randomDataService = new RandomDataService();

            Assert.ThrowsAsync <ArgumentOutOfRangeException>("minSeconds", () => randomDataService.RandomDelay(-1, 0));
        }