public async Task TestConfirmationPostWhenPaymentOther2() { // Arrange OrderData[1].CreatorId = "Creator1"; OrderData[1].Status = OrderStatusCodes.Created; OrderData[1].PaymentType = PaymentTypeCodes.Other; Controller.ErrorMessage = null; var orderDetails = CreateValidEntities.OrderDetails(2); orderDetails.OtherPaymentInfo.PaymentType = "SomethingElse"; orderDetails.ClientInfo.ClientId = null; OrderData[1].SaveDetails(orderDetails); // Act var controllerResult = await Controller.Confirmation(2, true); // Assert Controller.ErrorMessage.ShouldBeNull(); OrderData[1].GetOrderDetails().Payment.AccountName.ShouldBeNull(); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); MockFinancialService.Verify(a => a.GetAccountName(It.IsAny <string>()), Times.Never); MockOrderMessagingService.Verify(a => a.EnqueueBillingMessage(OrderData[1], It.IsAny <string>()), Times.Never); MockOrderService.Verify(a => a.UpdateTestsAndPrices(OrderData[1]), Times.Once); MockOrderService.Verify(a => a.UpdateAdditionalInfo(OrderData[1]), Times.Once); MockLabworksService.Verify(a => a.GetClientDetails(It.IsAny <string>()), Times.Never); MockOrderMessagingService.Verify(a => a.EnqueueCreatedMessage(OrderData[1]), Times.Once); var redirectResult = Assert.IsType <RedirectToActionResult>(controllerResult); redirectResult.ActionName.ShouldBe("Confirmed"); redirectResult.RouteValues["id"].ShouldBe(2); redirectResult.ControllerName.ShouldBeNull(); }
public async Task TestSaveWhenEditAndSuccess() { // Arrange OrderData[1].Status = OrderStatusCodes.Created; OrderData[1].CreatorId = "Creator1"; var model = new OrderSaveModel(); model.OrderId = 2; OrderData[1].SavedTestDetails.ShouldBeNull(); // Act var controllerResult = await Controller.Save(model); // Assert var result = Assert.IsType <JsonResult>(controllerResult); dynamic data = JObject.FromObject(result.Value); ((bool)data.success).ShouldBe(true); ((int)data.id).ShouldBe(2); MockOrderService.Verify(a => a.PopulateTestItemModel(It.IsAny <bool>()), Times.Once); MockOrderService.Verify(a => a.PopulateOrder(model, OrderData[1]), Times.Once); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); OrderData[1].SavedTestDetails.ShouldNotBeNull(); OrderData[1].GetTestDetails().Count.ShouldBe(10); }
public async Task TestConfirmationPostWhenUcdAccountVerified() { // Arrange OrderData[1].CreatorId = "Creator1"; OrderData[1].Status = OrderStatusCodes.Created; OrderData[1].PaymentType = PaymentTypeCodes.UcDavisAccount; Controller.ErrorMessage = null; var orderDetails = CreateValidEntities.OrderDetails(2); orderDetails.Payment.Account = "3-1234567"; orderDetails.Payment.AccountName = "WHAT!"; orderDetails.ClientInfo.ClientId = null; OrderData[1].SaveDetails(orderDetails); MockFinancialService.Setup(a => a.GetAccountName(It.IsAny <string>())).ReturnsAsync("My Fake Account"); // Act var controllerResult = await Controller.Confirmation(2, true); // Assert Controller.ErrorMessage.ShouldBeNull(); OrderData[1].GetOrderDetails().Payment.AccountName.ShouldBe("My Fake Account"); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); MockFinancialService.Verify(a => a.GetAccountName("3-1234567"), Times.Once); MockOrderService.Verify(a => a.UpdateAdditionalInfo(OrderData[1]), Times.Once); MockOrderService.Verify(a => a.UpdateTestsAndPrices(OrderData[1]), Times.Once); var redirectResult = Assert.IsType <RedirectToActionResult>(controllerResult); redirectResult.ActionName.ShouldBe("Confirmed"); redirectResult.RouteValues["id"].ShouldBe(2); redirectResult.ControllerName.ShouldBeNull(); }
public async Task TestSaveWhenCreateAndSuccess() { // Arrange var model = new OrderSaveModel(); model.OrderId = null; Order savedResult = null; MockDbContext.Setup(a => a.Add(It.IsAny <Order>())).Callback <Order>(r => savedResult = r); // Act var controllerResult = await Controller.Save(model); // Assert var result = Assert.IsType <JsonResult>(controllerResult); dynamic data = JObject.FromObject(result.Value); ((bool)data.success).ShouldBe(true); ((int)data.id).ShouldBe(0); //Because it would be set in the DB MockOrderService.Verify(a => a.PopulateTestItemModel(It.IsAny <bool>()), Times.Once); MockOrderService.Verify(a => a.PopulateOrder(model, It.IsAny <Order>()), Times.Once); MockDbContext.Verify(a => a.Add(It.IsAny <Order>()), Times.Once); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); savedResult.CreatorId.ShouldBe("Creator1"); savedResult.Creator.ShouldNotBeNull(); savedResult.Creator.Id.ShouldBe("Creator1"); savedResult.Status.ShouldBe(OrderStatusCodes.Created); savedResult.ShareIdentifier.ShouldNotBeNull(); }
public void TestCopySetsTheCreatorToCurrectUserWhenAdminIsTrueButNotAdminRole() { // Arrange Order savedResult = null; MockDbContext.Setup(a => a.Add(It.IsAny <Order>())).Callback <Order>(r => savedResult = r); var copiedOrder = CreateValidEntities.Order(7); copiedOrder.Creator = CreateValidEntities.User(5, true); OrderData[1].CreatorId = "xxx"; OrderData[1].Creator = CreateValidEntities.User(5); MockOrderService.Setup(a => a.DuplicateOrder(OrderData[1], true)).ReturnsAsync(copiedOrder); // Act var ex = Assert.ThrowsAsync <Exception>(async() => await Controller.Copy(SpecificGuid.GetGuid(2), true)); // Assert ex.Result.Message.ShouldBe("Permissions Missing"); MockOrderService.Verify(a => a.DuplicateOrder(OrderData[1], true), Times.Once); MockDbContext.Verify(a => a.Add(It.IsAny <Order>()), Times.Never); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Never); }
public async Task TestCopySetsTheCreatorToCurrectUserWhenNotAdmin() { // Arrange Order savedResult = null; MockDbContext.Setup(a => a.Add(It.IsAny <Order>())).Callback <Order>(r => savedResult = r); var copiedOrder = CreateValidEntities.Order(7); copiedOrder.Creator = CreateValidEntities.User(5, true); OrderData[1].CreatorId = "xxx"; OrderData[1].Creator = CreateValidEntities.User(5); MockOrderService.Setup(a => a.DuplicateOrder(OrderData[1], false)).ReturnsAsync(copiedOrder); // Act var controllerResult = await Controller.Copy(SpecificGuid.GetGuid(2)); // Assert MockOrderService.Verify(a => a.DuplicateOrder(OrderData[1], false), Times.Once); MockDbContext.Verify(a => a.Add(It.IsAny <Order>()), Times.Once); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); savedResult.ShouldNotBeNull(); savedResult.CreatorId.ShouldBe("Creator1"); savedResult.Creator.Id.ShouldBe("Creator1"); savedResult.ShareIdentifier.ShouldNotBe(SpecificGuid.GetGuid(2)); savedResult.SavedTestDetails.ShouldBeNull(); var redirectResult = Assert.IsType <RedirectToActionResult>(controllerResult); redirectResult.ActionName.ShouldBe("Edit"); redirectResult.ControllerName.ShouldBeNull(); redirectResult.RouteValues["id"].ShouldBe(savedResult.Id); }
public async Task TestIndexCallsPopulateTestItemModel() { // Arrange // Act await Controller.Index(); // Assert MockOrderService.Verify(a => a.PopulateTestItemModel(false), Times.Once); }
public async Task TestCopySetsTheCreatorToCorrectUserWhenAdminIsTrue() { MockClaimsPrincipal.Setup(a => a.IsInRole(RoleCodes.Admin)).Returns(true); Order savedResult = null; MockDbContext.Setup(a => a.Add(It.IsAny <Order>())).Callback <Order>(r => savedResult = r); var copiedOrder = CreateValidEntities.Order(7, true); var testItemModel = new List <TestItemModel>(); for (int i = 0; i < 5; i++) { testItemModel.Add(CreateValidEntities.TestItemModel(1)); } copiedOrder.SaveTestDetails(testItemModel); OrderData[1].SaveTestDetails(testItemModel); copiedOrder.Creator = CreateValidEntities.User(5, true); OrderData[1].CreatorId = "xxx"; OrderData[1].Creator = CreateValidEntities.User(5); MockOrderService.Setup(a => a.DuplicateOrder(OrderData[1], true)).ReturnsAsync(copiedOrder); // Act var controllerResult = await Controller.Copy(SpecificGuid.GetGuid(2), true); // Assert MockOrderService.Verify(a => a.DuplicateOrder(OrderData[1], true), Times.Once); MockDbContext.Verify(a => a.Add(It.IsAny <Order>()), Times.Once); MockDbContext.Verify(a => a.SaveChangesAsync(new CancellationToken()), Times.Once); savedResult.ShouldNotBeNull(); savedResult.CreatorId.ShouldBe("xxx"); savedResult.Creator.Id.ShouldBe("5"); savedResult.ShareIdentifier.ShouldNotBe(SpecificGuid.GetGuid(2)); savedResult.Status.ShouldBe(OrderStatusCodes.Confirmed); savedResult.GetOrderDetails().LabComments.ShouldContain("Duplicated from 2"); savedResult.GetTestDetails().Count.ShouldBe(5); var redirectResult = Assert.IsType <RedirectToActionResult>(controllerResult); redirectResult.ActionName.ShouldBe("AddRequestNumber"); redirectResult.ControllerName.ShouldBe("Lab"); redirectResult.RouteValues["id"].ShouldBe(savedResult.Id); MockClaimsPrincipal.Verify(a => a.IsInRole(RoleCodes.Admin), Times.Once); }
public async Task TestIndexReturnsViewWithExpectedData() { // Arrange // Act var controllerResult = await Controller.Index(); // Assert MockOrderService.Verify(a => a.PopulateTestItemModel(false), Times.Once); var result = Assert.IsType <ViewResult>(controllerResult); var resultModel = Assert.IsType <TestItemModel[]>(result.Model); resultModel.Length.ShouldBe(4); foreach (var testItemModel in resultModel) { testItemModel.Public.ShouldBe(true); } }
public async Task TestConfirmationGetReturnsView() { // Arrange OrderData[1].CreatorId = "Creator1"; var orderDetails = CreateValidEntities.OrderDetails(2); orderDetails.Quantity = 5; OrderData[1].SaveDetails(orderDetails); // Act var controllerResult = await Controller.Confirmation(2); // Assert var result = Assert.IsType <ViewResult>(controllerResult); var resultModel = Assert.IsType <OrderReviewModel>(result.Model); resultModel.Order.ShouldBe(OrderData[1]); resultModel.OrderDetails.Quantity.ShouldBe(5); MockOrderService.Verify(a => a.UpdateTestsAndPrices(OrderData[1]), Times.Once); }
public async Task TestEditReturnsViewWithExpectedResults() { // Arrange OrderData[1].CreatorId = "Creator1"; OrderData[1].Status = OrderStatusCodes.Created; OrderData[1].Creator = CreateValidEntities.User(7); // Act var controllerResult = await Controller.Edit(2); // Assert MockOrderService.Verify(a => a.PopulateTestItemModel(It.IsAny <bool>()), Times.Once); MockLabworksService.Verify(a => a.GetPrice("PROC"), Times.Once); var result = Assert.IsType <ViewResult>(controllerResult); var model = Assert.IsType <OrderEditModel>(result.Model); model.Order.ShouldNotBeNull(); model.Order.Id.ShouldBe(2); model.TestItems.Length.ShouldBe(10); model.InternalProcessingFee.ShouldBe(6m); model.ExternalProcessingFee.ShouldBe(12m); model.Defaults.DefaultEmail.ShouldBe("*****@*****.**"); }
public async Task CreateCallsOrderService() { var controllerResult = await Controller.Create(); MockOrderService.Verify(a => a.PopulateTestItemModel(It.IsAny <bool>()), Times.Once); }