public async Task CreateEditDeleteAsync()
        {
            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            // Arrange
            var bankAccountController = new BankAccountController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                                    null, null, null, null, null, null, null, null));
            var transactionController = new TransactionController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                                    null, null, null, null, null, null, null, null));

            var bankAccount = new BankAccount();
            var result      = await bankAccountController.Create(bankAccount);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);


            // Arrange
            var bankAccountId = bankAccount.Id;

            // Act
            var transactionViewModel = new TransactionViewModel
            {
                BankAccountId = bankAccountId,
                Amount        = "100",
                IsDeposition  = true
            };

            result = await transactionController.Create(transactionViewModel);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);

            var transactionId = transactionViewModel.Id;

            // Act
            result = await transactionController.Details(transactionId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act

            result = await transactionController.Edit(transactionId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act
            result = await transactionController.Edit(transactionId, transactionViewModel);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);

            // Act
            result = await bankAccountController.DeleteConfirmed(bankAccountId);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
        }
        public void CreateBankAccount()
        {
            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            // Arrange
            var bankAccountController = new BankAccountController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                                    null, null, null, null, null, null, null, null));

            // Act
            var result = bankAccountController.Create() as ViewResult;

            // Assert
            Assert.IsType <ViewResult>(result);
        }
예제 #3
0
        public async void Create_Errors()
        {
            BankAccountControllerMockFacade mock = new BankAccountControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiBankAccountServerResponseModel> >(null as ApiBankAccountServerResponseModel);
            var mockRecord   = new ApiBankAccountServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBankAccountServerResponseModel> >(mockResponse.Object));
            BankAccountController controller = new BankAccountController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiBankAccountServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>()));
        }
예제 #4
0
        public async void Create_No_Errors()
        {
            BankAccountControllerMockFacade mock = new BankAccountControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiBankAccountServerResponseModel> .CreateResponse(null as ApiBankAccountServerResponseModel);

            mockResponse.SetRecord(new ApiBankAccountServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBankAccountServerResponseModel> >(mockResponse));
            BankAccountController controller = new BankAccountController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiBankAccountServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiBankAccountServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>()));
        }