public async Task Post_ReturnsCreatedResult_WhenFormIsValid() { var mockService = new Mock <ITokenCosmosDBService>(); mockService.Setup(x => x.AddCustomerDetails(It.IsAny <CustomerDetails>())).Returns(Task.FromResult(1)); var controller = new CustomerTokenDashboardController(mockService.Object); var customerDetails = new CustomerDetails { Name = "Raji", AccountNumber = 123456, Age = 30, CustomerType = "Guest", ServiceType = ServiceType.BankTransaction, SocialNumber = "111111" }; // Act var actual = await controller.Post(customerDetails) as ObjectResult; // Asset Assert.AreEqual(StatusCodes.Status201Created, actual.StatusCode); Assert.AreEqual(1, actual.Value); }
public async Task Post_ReturnsBadRequestResult_WhenFormIsInValid() { var mockService = new Mock <ITokenCosmosDBService>(); mockService.Setup(x => x.AddCustomerDetails(It.IsAny <CustomerDetails>())).Returns(Task.FromResult(1)); var controller = new CustomerTokenDashboardController(mockService.Object); controller.ModelState.AddModelError("ServiceType", "Required"); var customerDetails = new CustomerDetails { Name = "Raji" }; // Act var actual = await controller.Post(customerDetails) as ObjectResult; // Asset Assert.AreEqual(StatusCodes.Status400BadRequest, actual.StatusCode); }