public async Task ContentRulesSuccess_SavesToDraft()
        {
            var summary = new PrenotificationRulesSummary();
            var message = new PerformPrenotificationContentValidation(summary, notificationId, new DataTable(), "Test", false);

            var movements = new List <PrenotificationMovement>()
            {
                new PrenotificationMovement()
                {
                    NotificationNumber = "GB 0001 123456",
                    ShipmentNumber     = 1,
                    Quantity           = 1m,
                    Unit           = ShipmentQuantityUnits.Tonnes,
                    PackagingTypes = new List <PackagingType>()
                    {
                        PackagingType.Drum, PackagingType.Bag
                    },
                    ActualDateOfShipment = SystemTime.UtcNow
                }
            };

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(movements);
            A.CallTo(() => contentRule.GetResult(A <List <PrenotificationMovement> > .Ignored, notificationId))
            .Returns(new PrenotificationContentRuleResult <PrenotificationContentRules>(PrenotificationContentRules.MissingData,
                                                                                        MessageLevel.Success, "Test", 0));

            var response = await handler.HandleAsync(message);

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

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

            var response = await handler.HandleAsync(message);

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

            A.CallTo(() => mapper.Map(A <DataTable> .Ignored)).Returns(A.CollectionOfFake <PrenotificationMovement>(5).ToList());
            A.CallTo(() => contentRule.GetResult(A <List <PrenotificationMovement> > .Ignored, notificationId))
            .Returns(new PrenotificationContentRuleResult <PrenotificationContentRules>(PrenotificationContentRules.MissingData,
                                                                                        MessageLevel.Error, "Missing data", 0));

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
            A.CallTo(() => repository.AddPrenotifications(A <Guid> .Ignored, A <List <PrenotificationMovement> > .Ignored, "Test")).MustNotHaveHappened();
        }
        public async Task <PrenotificationRulesSummary> GetPrenotificationValidationSummary(HttpPostedFileBase file, Guid notificationId, string token)
        {
            var fileRulesSummary = await fileValidator.GetFileRulesSummary(file, BulkFileType.Prenotification, token);

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

            var rulesSummary = new PrenotificationRulesSummary(fileRulesSummary.FileRulesResults);

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

            return(rulesSummary);
        }
        public async Task MissingNotificationNumber_ContentRulesFailed()
        {
            var summary = new PrenotificationRulesSummary();
            var message = new PerformPrenotificationContentValidation(summary, notificationId, new DataTable(), "Test", false);

            var movements = new List <PrenotificationMovement>()
            {
                new PrenotificationMovement()
                {
                    MissingNotificationNumber = true
                }
            };

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

            var response = await handler.HandleAsync(message);

            Assert.False(response.IsContentRulesSuccess);
        }