private async Task TestCreatePOST()
        {
            // Arrange
            var id       = Guid.Empty;
            var showroom = GetShowroom();
            var car      = GetCar();
            var model    = GetCarEditViewModel(car);

            MockMapper
            .Setup(_ => _.Map <Car>(model))
            .Returns(car);

            MockShowroomData
            .Setup(_ => _.GetById(model.ShowroomId))
            .ReturnsAsync(showroom);

            // Act
            //ControllerUnderTest.ModelState.AddModelError("key", "error"); // force invalid input
            dynamic response = await ControllerUnderTest.Create(model);

            // Assert
            MockShowroomData.Verify(_ => _.GetById(model.ShowroomId), Times.Once);
            MockMapper.Verify(_ => _.Map <Car>(model), Times.Once);

            Assert.True(response.RouteValues.Values[0].Equals(car.Id));
            Assert.True(response.ActionName.Equals("Details"));
        }
        private void TestDetailsGET()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarDetailsViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <CarDetailsViewModel>(car))
            .Returns(model);

            // Act
            dynamic response = ControllerUnderTest.Details(id);

            // Assert
            MockCarData.Verify(_ => _.GetById(id), Times.Once);
            MockMapper.Verify(_ => _.Map <CarDetailsViewModel>(car), Times.Once);

            Assert.True(response.Model.Id.Equals(model.Id));
            Assert.True(response.Model.Brand.Equals(model.Brand));
            Assert.True(response.Model.Model.Equals(model.Model));
            Assert.True(response.Model.VIN.Equals(model.VIN));
        }
 private void VerifyMocksCreate(Times methodCalls)
 {
     VerifyMocksGeneral(methodCalls);
     MockUnitOfWork.Verify(x => x.CategoryRepository.Create(fixture.CreateCategory), methodCalls);
     MockMapper.Verify(x => x.Map <MainCategoryDto>(fixture.CreateCategory), methodCalls);
     MockMapper.Verify(x => x.Map <MainCategory>(fixture.CreateCategoryDto), methodCalls);
 }
Beispiel #4
0
 private void VerifyMocksGeneral(UserDto mappedUser, Times methodCalls)
 {
     MockUnitOfWork.Verify(x =>
                           x.UserRepository.SingleOrDefaultAsync(It.IsAny <Expression <Func <User, bool> > >()), Times.Once());
     MockUnitOfWork.Verify(x => x.CommitAsync(), methodCalls);
     MockMapper.Verify(x => x.Map <User>(mappedUser), methodCalls);
     mockPasswordService.Verify(x => x.CreatePasswordHash(fixture.Password), methodCalls);
 }
 private void VerifyMocksUpdate(int userId, int walletId, Wallet walletToUpdate, Times times)
 {
     VerifyMockGetWallet(walletId, Times.Once());
     VerifyMockGetUser(userId, times);
     VerifyMockCommit(times);
     MockUnitOfWork.Verify(x => x.WalletRepository.Update(walletToUpdate), times);
     MockMapper.Verify(x => x.Map(fixture.UpdateWalletDto, walletToUpdate), times);
 }
 private void VerifyMocksCreate(int userIdToReturn, Times mapperCalls)
 {
     VerifyMockGetUser(userIdToReturn, Times.Once());
     VerifyMockCommit(mapperCalls);
     MockUnitOfWork.Verify(x => x.WalletRepository.Create(fixture.DefaultWallet), mapperCalls);
     MockMapper.Verify(x => x.Map <Wallet>(fixture.DefaultWalletDto), mapperCalls);
     MockMapper.Verify(x => x.Map <WalletDto>(fixture.DefaultWallet), mapperCalls);
 }
Beispiel #7
0
 private void VerifyMocks(Wallet userWallet, int userId, Operation createOperation,
                          OperationDto createOperationDto, Times methodCalls)
 {
     MockUnitOfWork.Verify(x => x.UserRepository.GetAsync(userId));
     MockUnitOfWork.Verify(x => x.OperationRepository.Create(createOperation), methodCalls);
     MockUnitOfWork.Verify(x => x.WalletRepository.Update(userWallet), methodCalls);
     MockUnitOfWork.Verify(x => x.CommitAsync(), methodCalls);
     MockMapper.Verify(x => x.Map <Operation>(createOperationDto), methodCalls);
     MockMapper.Verify(x => x.Map <OperationDto>(createOperation), methodCalls);
 }
        public async Task GetWalletAsync_GetWallet_WalletReturned()
        {
            SetupMocksGet <Wallet, WalletDto>(fixture.DefaultUser, fixture.DefaultWalletDto, fixture.DefaultWallet);

            var wallet = await service.GetWalletAsync(fixture.DefaultUser.UserId, fixture.DefaultWalletDto.WalletId);

            Assert.Equal(wallet, fixture.DefaultWalletDto);
            VerifyMockGetWallet(fixture.DefaultWalletDto.WalletId, Times.Once());
            MockMapper.Verify(x => x.Map <WalletDto>(fixture.DefaultWallet), Times.Once);
        }
        public async Task GetAllWalletsAsync_GetWallets_AllWalletsReturned()
        {
            SetupMocksGet <IEnumerable <Wallet>, IEnumerable <WalletDto> >(fixture.UserWithWallets,
                                                                           fixture.UserWalletsDtos);

            var wallets = await service.GetAllWalletsAsync(fixture.UserWithWallets.UserId, fixture.PaginationFilter);

            Assert.Equal(wallets, fixture.UserWalletsDtos);
            VerifyMockGetUser(fixture.UserWithWallets.UserId, Times.Once());
            MockMapper.Verify(x => x.Map <IEnumerable <WalletDto> >(fixture.UserWithWallets.Wallets), Times.Once);
        }
Beispiel #10
0
 internal void VeriyfAutoMapperCalledOnce()
 {
     MockMapper.Verify(x => x.Map <Commitments>(GetApprenticeshipResponse), Times.Once);
 }
 private void VerifyMocksUpdate <TUpdatedCategory>()
 {
     VerifyMocksGeneral(Times.Once());
     MockUnitOfWork.Verify(x => x.CategoryRepository.Update(It.IsAny <MainCategory>()), Times.Once);
     MockMapper.Verify(x => x.Map(It.IsAny <UpdateCategoryDto>(), It.IsAny <TUpdatedCategory>()), Times.Once);
 }