コード例 #1
0
        public async Task GetByIdAsync_Should_ReturnElementWithSpecificId()
        {
            var inputId = Guid.NewGuid();
            var entity1 = new Persistence.Entities.Rental
            {
                Id        = inputId,
                PaidMoney = 10
            };
            var entity2 = new Persistence.Entities.Rental
            {
                Id        = Guid.NewGuid(),
                PaidMoney = 20
            };
            var entities = new List <Persistence.Entities.Rental> {
                entity1, entity2
            };
            await _testContext.Rentals.AddRangeAsync(entities, _cancellationToken);

            await _testContext.SaveChangesAsync(_cancellationToken);

            var result = await _sut.RentalRepository.GetByIdAsync(inputId, _cancellationToken);

            result.Id.Should().Be(inputId);
            result.PaidMoney.Should().Be(entity1.PaidMoney);
            result.Should().BeOfType <Rental>();
        }
コード例 #2
0
        public async Task GetAllForClientAsync_Should_ReturnMappedListOfGameRentals_When_TheyHaveCorrectBoardGameId()
        {
            var inputClientId = Guid.NewGuid();
            var entity1       = new Persistence.Entities.Rental
            {
                Id          = Guid.NewGuid(),
                BoardGameId = inputClientId
            };
            var entity2 = new Persistence.Entities.Rental
            {
                Id       = Guid.NewGuid(),
                ClientId = inputClientId
            };
            var entities = new List <Persistence.Entities.Rental> {
                entity1, entity2
            };
            await _testContext.Rentals.AddRangeAsync(entities, _cancellationToken);

            await _testContext.SaveChangesAsync(_cancellationToken);

            var result = await _sut.RentalRepository.GetAllForClientAsync(inputClientId, _cancellationToken);

            result.Should().BeOfType <List <Rental> >();
            result.Should().NotContain(x => x.Id == entity1.Id);
            result.Should().Contain(x => x.Id == entity2.Id);
            result.Count.Should().Be(1);
        }
コード例 #3
0
        public void AddAsync_Should_ThrowArgumentException_When_ElementWithThisIdExist()
        {
            var rental         = new Rental(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), 15);
            var existingEntity = new Persistence.Entities.Rental
            {
                Id = rental.Id
            };

            _testContext.Rentals.Add(existingEntity);
            _testContext.SaveChanges();

            Func <Task> act = async() =>
            {
                await _sut.RentalRepository.AddAsync(rental, _cancellationToken);

                await _sut.SaveChangesAsync(_cancellationToken);
            };

            act.Should().Throw <ArgumentException>();
        }
コード例 #4
0
        public async Task GetByIdAsync_Should_ReturnNull_When_NoMatchingElementsFound()
        {
            var entity1 = new Persistence.Entities.Rental
            {
                Id        = Guid.NewGuid(),
                PaidMoney = 10
            };
            var entity2 = new Persistence.Entities.Rental
            {
                Id        = Guid.NewGuid(),
                PaidMoney = 20
            };
            var entities = new List <Persistence.Entities.Rental> {
                entity1, entity2
            };
            await _testContext.Rentals.AddRangeAsync(entities, _cancellationToken);

            await _testContext.SaveChangesAsync(_cancellationToken);

            var result = await _sut.RentalRepository.GetByIdAsync(Guid.NewGuid(), _cancellationToken);

            result.Should().BeNull();
        }