Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public async Task TestViewMessageReturnsView()
        {
            // Arrange
            var mail = new List <MailMessage>();

            for (int i = 0; i < 5; i++)
            {
                var mm = CreateValidEntities.MailMessage(i + 1);
                mm.Order  = CreateValidEntities.Order(i + 1);
                mm.User   = UserData[i % 2];
                mm.Sent   = null;
                mm.SentAt = DateTime.UtcNow.AddDays(-35);
                mail.Add(mm);
            }

            MockDbContext.Setup(a => a.MailMessages).Returns(mail.AsQueryable().MockAsyncDbSet().Object);



            // Act
            var controllerResult = await Controller.ViewMessage(3);

            // Assert
            var viewResult  = Assert.IsType <ViewResult>(controllerResult);
            var modelResult = Assert.IsType <MailMessage>(viewResult.Model);

            modelResult.ShouldNotBeNull();
            modelResult.Id.ShouldBe(3);
        }
Ejemplo n.º 5
0
        public async Task TestMailQueueReturnsView1()
        {
            // Arrange
            var mail = new List <MailMessage>();

            for (int i = 0; i < 10; i++)
            {
                var mm = CreateValidEntities.MailMessage(i + 1);
                mm.Order = CreateValidEntities.Order(i + 1);
                mm.User  = UserData[i % 2];
                mail.Add(mm);
            }

            MockDbContext.Setup(a => a.MailMessages).Returns(mail.AsQueryable().MockAsyncDbSet().Object);

            for (int i = 0; i < 3; i++)
            {
                mail[i].Order = CreateValidEntities.Order(2);
            }

            // Act
            var controllerResult = await Controller.MailQueue(mail[0].Order.Id);

            // Assert
            var viewResult  = Assert.IsType <ViewResult>(controllerResult);
            var modelResult = Assert.IsType <List <MailMessage> >(viewResult.Model);

            modelResult.ShouldNotBeNull();
            modelResult.Count.ShouldBe(3);
            modelResult[0].Id.ShouldBe(1);
            modelResult[0].Order.Id.ShouldBe(2);
        }
Ejemplo n.º 6
0
        public void GetIMSIInfo_test_with_null_result()
        {
            MockDbContext.Setup(s => s.Single <IMSIInfo>(It.IsAny <Expression <Func <IMSIInfo, bool> > >()));
            var result = SMSService.GetMobile(IMSI_EXAMPLE);

            Assert.Null(result);
        }
Ejemplo n.º 7
0
        public void GetIMSIInfo_test()
        {
            IMSIInfo imsiInfo = new IMSIInfo()
            {
                Id = 1, Mobile = "18660127508", IMSI = "12145785421"
            };

            MockDbContext.Setup(s => s.Single <IMSIInfo>(It.IsAny <Expression <Func <IMSIInfo, bool> > >())).Returns(imsiInfo);
            var result = SMSService.GetMobile(IMSI_EXAMPLE);

            Assert.Equal(1, result.Id);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void UpdateSMSLog_Input_smsStatus_smsContent()
        {
            long            logId        = 11;
            SMSChargeStatus chargeStatus = SMSChargeStatus.Sent;
            string          content      = "sms message";
            SMSDirection    smsDirection = SMSDirection.Receive;

            SMSChannelLog smsChannelLog = new SMSChannelLog
            {
                ID           = 11,
                ChargeStatus = SMSChargeStatus.Initial
            };

            MockDbContext.Setup(s => s.Single <SMSChannelLog>(It.IsAny <Expression <Func <IMSIInfo, bool> > >())).Returns(smsChannelLog);
            MockDbContext.Setup(s => s.Update <SMSChannelLog>(It.IsAny <SMSChannelLog>())).Returns(1);
            MockDbContext.Setup(s => s.Add <SMSLog>(It.IsAny <SMSLog>())).Returns(1);
            this.SMSService.UpdateSMSLog(logId, chargeStatus, content, smsDirection, false, "", "", "", "");
        }