Exemplo n.º 1
0
        public async Task MultpliplePeopleMatchingFilter_GetMultipleByFilterWithOrderBy_AllMatchingFilterResultsReturnedOrdered()
        {
            //Arrange
            const byte numberOfPeople = 10;
            const byte minimalAge     = 10;
            var        repository     = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var localRepo = new List <CompsiteKeyPerson>(numberOfPeople);

            for (var i = 0; i < numberOfPeople; i++)
            {
                var  postfix = (i + 1).ToString();
                byte age     = (byte)(i + minimalAge);
                var  person  = CompositeKeyRepositoryArranger.CreatePerson(age, postfix, postfix);
                localRepo.Add(person);
                var addOpRes = await repository.TryAddAsync(person)
                               .ConfigureAwait(false);

                Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            }

            //Act
            var getOpRes = await repository.TryGetMultipleAsync(p => p.Age >= minimalAge,
                                                                orderBy : people => people.OrderBy(p => p.Age))
                           .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(numberOfPeople, getOpRes.Value.TotalNumberOfItems);
            Assert.IsTrue(localRepo.OrderBy(p => p.Age).SequenceEqual(getOpRes.Value.Items));
        }
Exemplo n.º 2
0
        public async Task ExistingPerson_Update_Updated()
        {
            //Arrange
            const string updatedValue = "Updated";
            var          repository   = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await repository.TryAddAsync(person)
                           .ConfigureAwait(false);

            var existingEntityId = new object[] { addOpRes.Value.Key1, addOpRes.Value.Key2, addOpRes.Value.Key3 };

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var getOpRes = await repository.TryGetSingleAsync(existingEntityId)
                           .ConfigureAwait(false);

            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(getOpRes.Value, addOpRes.Value);

            //Act
            var updateOpRes = await repository.TryUpdateAsync(existingEntityId,
                                                              p =>
            {
                p.FirstName = updatedValue;
                p.LastName  = updatedValue;
            }).ConfigureAwait(false);

            //Assert
            Assert.IsTrue(updateOpRes, updateOpRes.ErrorMessage);
            getOpRes = await repository.TryGetSingleAsync(existingEntityId).ConfigureAwait(false);

            Assert.AreEqual(getOpRes.Value.FirstName, updatedValue);
            Assert.AreEqual(getOpRes.Value.LastName, updatedValue);
        }
Exemplo n.º 3
0
        public async Task NonExistingPerson_Add_Added()
        {
            //Arrange
            var repository = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync()
                             .ConfigureAwait(false);

            var person = CompositeKeyRepositoryArranger.CreatePerson();

            //Act
            var opRes = await repository.TryAddAsync(person)
                        .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(opRes, opRes.ErrorMessage);
        }
        public async Task GetMultipleWithPaging_SingleItemPerPage_ExpectedNumberOfPagesWithResultsReturned()
        {
            //Arrange
            const byte numberOfPeople = 10;
            const byte minimalAge     = 10;
            var        repository     = await CompositeKeyRepositoryArranger
                                        .TryGetRepositoryAsync()
                                        .ConfigureAwait(false);

            for (var i = 0; i < numberOfPeople; i++)
            {
                var  postfix  = (i + 1).ToString();
                byte age      = (byte)(i + minimalAge);
                var  person   = CompositeKeyRepositoryArranger.CreatePerson(age, postfix, postfix);
                var  addOpRes = await repository.TryAddAsync(person)
                                .ConfigureAwait(false);

                Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            }

            const int itemsPerPage         = 1;
            int       expctedNumberOfPages = 10;
            int       currentPage          = 1;

            for (int i = 0; i < expctedNumberOfPages; i++)
            {
                //Act
                var getOpRes = await repository.TryGetMultipleAsync(
                    p => p.Age >= minimalAge,
                    pagingParams : new Storage.Common.DataTypes.PagingParams(currentPage, itemsPerPage))
                               .ConfigureAwait(false);

                ++currentPage;

                //Assert
                Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
                Assert.AreEqual(getOpRes.Value.ItemsPerPage, itemsPerPage);
                Assert.AreEqual(getOpRes.Value.TotalNumberOfPages, expctedNumberOfPages);
                Assert.AreEqual(getOpRes.Value.Items.Count, itemsPerPage);
                Assert.AreEqual(getOpRes.Value.TotalNumberOfItems, numberOfPeople);
            }
        }
Exemplo n.º 5
0
        public async Task ExistingPerson_GetSingle_ReturnedExistingPerson()
        {
            //Arrange
            var repository = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await repository.TryAddAsync(person)
                           .ConfigureAwait(false);

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var existingEntityId = new object[] { addOpRes.Value.Key1, addOpRes.Value.Key2, addOpRes.Value.Key3 };

            //Act
            var getOpRes = await repository.TryGetSingleAsync(existingEntityId)
                           .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(getOpRes.Value, addOpRes.Value);
        }