public async Task ContentRulesSuccess_SavesToDraft()
        {
            var notificationId = Guid.NewGuid();
            var summary        = new ReceiptRecoveryRulesSummary();
            var message        = new PerformReceiptRecoveryContentValidation(summary, notificationId, new DataTable(), "Test", false);

            var movements = new List <ReceiptRecoveryMovement>()
            {
                new ReceiptRecoveryMovement()
                {
                    NotificationNumber = "GB 0001 123456",
                    ShipmentNumber     = 1,
                    Quantity           = 1m,
                    Unit                  = ShipmentQuantityUnits.Tonnes,
                    ReceivedDate          = SystemTime.UtcNow,
                    RecoveredDisposedDate = SystemTime.UtcNow
                }
            };

            A.CallTo(() => movementRepository.GetAllMovements(notificationId)).Returns(GetRepoMovements());
            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(movements);
            A.CallTo(() => contentRule.GetResult(A <List <ReceiptRecoveryMovement> > .Ignored, notificationId))
            .Returns(new ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules>(ReceiptRecoveryContentRules.MaximumShipments,
                                                                                        MessageLevel.Success, "Test", 0));

            var response = await handler.HandleAsync(message);

            Assert.True(response.IsContentRulesSuccess);
            A.CallTo(() => repository.AddReceiptRecovery(A <Guid> .Ignored, A <List <ReceiptRecoveryMovement> > .Ignored, "Test"))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task ExceedsMaxRows_ContentRulesFailed()
        {
            var notificationId = Guid.NewGuid();
            var summary        = new ReceiptRecoveryRulesSummary();
            var message        = new PerformReceiptRecoveryContentValidation(summary, notificationId, new DataTable(), "Test", false);

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored))
            .Returns(A.CollectionOfFake <ReceiptRecoveryMovement>(MaxShipments + 1).ToList());

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
        }
        public async Task ContentRulesFailed_DoesNotSaveToDraft()
        {
            var notificationId = Guid.NewGuid();
            var summary        = new ReceiptRecoveryRulesSummary();
            var message        = new PerformReceiptRecoveryContentValidation(summary, notificationId, new DataTable(), "Test", false);

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(A.CollectionOfFake <ReceiptRecoveryMovement>(5).ToList());
            A.CallTo(() => contentRule.GetResult(A <List <ReceiptRecoveryMovement> > .Ignored, notificationId))
            .Returns(new ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules>(ReceiptRecoveryContentRules.MaximumShipments,
                                                                                        MessageLevel.Error, "Missing data", 0));

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
            A.CallTo(() => repository.AddReceiptRecovery(A <Guid> .Ignored, A <List <ReceiptRecoveryMovement> > .Ignored, "Test")).MustNotHaveHappened();
        }
コード例 #4
0
        public async Task <ReceiptRecoveryRulesSummary> GetValidationSummary(HttpPostedFileBase file, Guid notificationId, string token)
        {
            var fileRulesSummary = await fileValidator.GetFileRulesSummary(file, BulkFileType.ReceiptRecovery, token);

            var extension = Path.GetExtension(file.FileName);
            var isCsv     = extension == ".csv";

            var rulesSummary = new ReceiptRecoveryRulesSummary(fileRulesSummary.FileRulesResults);

            if (rulesSummary.IsFileRulesSuccess)
            {
                rulesSummary =
                    await
                    mediator.SendAsync(new PerformReceiptRecoveryContentValidation(rulesSummary,
                                                                                   notificationId, fileRulesSummary.DataTable, file.FileName, isCsv));
            }

            return(rulesSummary);
        }
        public async Task MissingReceiptAndRecoveryData_ContentRulesFailed()
        {
            var movements = new List <ReceiptRecoveryMovement>()
            {
                new ReceiptRecoveryMovement()
                {
                    NotificationNumber           = "GB 0001 123456",
                    ShipmentNumber               = 1,
                    MissingReceivedDate          = true,
                    MissingRecoveredDisposedDate = true,
                    MissingQuantity              = false,
                    MissingUnits = false
                },
                new ReceiptRecoveryMovement()
                {
                    NotificationNumber           = "GB 0001 123456",
                    ShipmentNumber               = 2,
                    MissingReceivedDate          = true,
                    MissingRecoveredDisposedDate = true,
                    MissingQuantity              = true,
                    MissingUnits = false
                },
                new ReceiptRecoveryMovement()
                {
                    NotificationNumber  = "GB 0001 123456",
                    ShipmentNumber      = 3,
                    MissingReceivedDate = false,
                    MissingQuantity     = false,
                    MissingUnits        = true
                }
            };

            var notificationId = Guid.NewGuid();
            var summary        = new ReceiptRecoveryRulesSummary();
            var message        = new PerformReceiptRecoveryContentValidation(summary, notificationId, new DataTable(), "Test", false);

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(movements);

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
        }
        public async Task MissingNotificationNumber_ContentRulesFailed()
        {
            var notificationId = Guid.NewGuid();
            var summary        = new ReceiptRecoveryRulesSummary();
            var message        = new PerformReceiptRecoveryContentValidation(summary, notificationId, new DataTable(), "Test", false);

            var movements = new List <ReceiptRecoveryMovement>()
            {
                new ReceiptRecoveryMovement()
                {
                    ShipmentNumber            = 1,
                    MissingShipmentNumber     = false,
                    MissingNotificationNumber = true
                }
            };

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(movements);

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
        }