public void PostTransactionTest() { var newAccountDetails = new NewAccountDetailEntity { AccountType = "Fixed Deposit", CustomerId = "3", DepositAmount = "1000" }; var accountServiceMock = new Mock<IAccountService>(); accountServiceMock.Setup(ser => ser.CreateAccount(newAccountDetails)).Returns(new AccountEntity { Account_Id = 101, Account_Balance = 1000, Account_Number = "1234-12345", Account_Type = "Fixed Deposit", Customer_Id = 3 }); var controller = new AccountController(accountServiceMock.Object) { Configuration = new HttpConfiguration(), Request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri($"http://{Localhost}/api/account") } }; controller.Configuration.MapHttpAttributeRoutes(); controller.Configuration.EnsureInitialized(); controller.RequestContext.RouteData = new HttpRouteData(new HttpRoute(), new HttpRouteValueDictionary { {"controller", "Account"} }); var httpResponse = controller.PostAccount(newAccountDetails); var createdAccount = httpResponse.Content.ReadAsAsync<AccountEntity>().Result; Assert.IsNotNull(createdAccount, "Created account was null or empty"); Assert.AreEqual(createdAccount.Account_Id, 101, "Account ID are not same"); Assert.AreEqual(createdAccount.Account_Balance, 1000, "Account balance are not same"); Assert.AreEqual(createdAccount.Customer_Id, 3, "Customer ID are not same"); Assert.AreSame(createdAccount.Account_Number, "1234-12345", "Account number are not same"); Assert.AreSame(createdAccount.Account_Type, "Fixed Deposit", "Account type are not same"); }