Exemple #1
0
        public async Task UpdateAsync_CityValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var concert  = new ConcertUpdateModel();
            var expected = fixture.Create <string>();

            var cityGetService = new Mock <ICityGetService>();

            cityGetService
            .Setup(x => x.ValidateAsync(concert))
            .Throws(new InvalidOperationException(expected));

            var bandGetService = new Mock <IBandGetService>();

            bandGetService.Setup(x => x.ValidateAsync(concert)).Throws(new InvalidOperationException(expected));


            var concertDataAccess = new Mock <IConcertDataAccess>();

            var concertGetService = new ConcertUpdateService(concertDataAccess.Object, cityGetService.Object, bandGetService.Object);

            // Act
            var action = new Func <Task>(() => concertGetService.UpdateAsync(concert));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            concertDataAccess.Verify(x => x.UpdateAsync(concert), Times.Never);
        }
Exemple #2
0
        public async Task UpdateAsync_ConcertValidationSucceed_CreatesConcert()
        {
            // Arrange
            var concert  = new ConcertUpdateModel();
            var expected = new Concert();

            var cityGetService = new Mock <ICityGetService>();

            cityGetService.Setup(x => x.ValidateAsync(concert));

            var bandGetService = new Mock <IBandGetService>();

            bandGetService.Setup(x => x.ValidateAsync(concert));

            var concertDataAccess = new Mock <IConcertDataAccess>();

            concertDataAccess.Setup(x => x.UpdateAsync(concert)).ReturnsAsync(expected);

            var concertGetService = new ConcertUpdateService(concertDataAccess.Object, cityGetService.Object, bandGetService.Object);

            // Act
            var result = await concertGetService.UpdateAsync(concert);

            // Assert
            result.Should().Be(expected);
        }
        public async Task <Concert> InsertAsync(ConcertUpdateModel concert)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Concert>(concert));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Concert>(result.Entity));
        }
Exemple #4
0
        public async Task <Concert> CreateAsync(ConcertUpdateModel concert)
        {
            await BandGetService.ValidateAsync(concert);

            await CityGetService.ValidateAsync(concert);

            return(await ConcertDataAccess.InsertAsync(concert));
        }
        public async Task <Concert> UpdateAsync(ConcertUpdateModel concert)
        {
            var existing = await this.Get(concert);

            var result = this.Mapper.Map(concert, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Concert>(result));
        }