예제 #1
0
        public void ShouldReturnErrorsUsingClosedXMLAndCustomMessages()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddWorksheetParser <FakeClass>(x => x.WithParser <ClosedXmlParser <FakeClass> >().WithMap <MyWorksheetMap>().WithMessages <CustomMessages>());

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var expectedItens = new List <FakeClass>
            {
                FakeClass.CreateItem(),
                FakeClass.CreateItem(false, false, false),
                FakeClass.CreateItem(false, false, true)
            };

            var parser = serviceProvider.GetService <WorksheetParser <FakeClass> >();

            expectedItens.ForEach(x => x.Bonus *= 0.1M);
            var validationResult = new ValidationResult <FakeClass>();
            var error            = new Error("Can't not be null field TX_NAME", 3, 2);

            validationResult.AddError(error);
            validationResult.AddItem(expectedItens.First());
            validationResult.AddItem(expectedItens.Last());

            var headers = new MyWorksheetMap().GetFields().Select(s => s.Name).ToList();

            using var worksheet = CreateStream(expectedItens, headers);
            var itens = parser.Parse(worksheet, worksheetName);

            itens.Should().BeEquivalentTo(validationResult);
        }
        public void ShouldAddItem()
        {
            var fakeClass = CreateItem();
            var itens     = new List <FakeClass> {
                fakeClass
            };

            validationResult.AddItem(fakeClass);
            validationResult.Itens.Should().BeEquivalentTo(itens);
        }
예제 #3
0
        public void ShouldParseSheetUsingClosedXML()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddWorksheetParser <FakeClass>(x => x.WithParser <ClosedXmlParser <FakeClass> >().WithMap <MyWorksheetMap>());

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var expectedItens = new List <FakeClass>();

            for (var i = 0; i < 5; i++)
            {
                expectedItens.Add(FakeClass.CreateItem(i % 2 == 0, i % 5 == 0));
            }

            var parser = serviceProvider.GetService <WorksheetParser <FakeClass> >();

            var headers = new MyWorksheetMap().GetFields().Select(s => s.Name).ToList();

            using var worksheet = CreateStream(expectedItens, headers);
            var itens = parser.Parse(worksheet, worksheetName);

            expectedItens.ForEach(x => x.Bonus = x.Bonus * 0.1M);
            var validationResult = new ValidationResult <FakeClass>();

            validationResult.AddItem(expectedItens);
            itens.Should().BeEquivalentTo(validationResult);
        }
        public void ShouldNotAddItensResultIfIsNotSuccess()
        {
            var validationAdded = new ValidationResult <FakeClass>();

            validationAdded.AddItem(CreateItem());
            validationAdded.AddError(CreateError());

            validationResult.AddResult(validationAdded);
            validationResult.Itens.Should().BeEmpty();
        }
예제 #5
0
 private void ValidateEmail(IUserService service, UserData dto, ValidationResult result)
 {
     if (service.IsExists(dto.Email))
     {
         result.AddItem(typeof(User),
                        BuildLocalizationKey("EmailUsed"),
                        ValidationItemType.Error,
                        Localize("EmailUsed"),
                        "Email");
     }
 }
        public void ShouldAddItensResultIfIsSuccess()
        {
            var item       = CreateItem();
            var validation = new ValidationResult <FakeClass>();

            validation.AddItem(item);

            validationResult.AddResult(validation);
            validationResult.Itens.Should().BeEquivalentTo(new List <FakeClass> {
                item
            });
        }
예제 #7
0
        public void ShouldCreateNewColumnsWithErrors()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddWorksheetParser <FakeClass>(x => x.WithParser <ClosedXmlParser <FakeClass> >().WithMap <MyWorksheetMap>());

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var expectedItens = new List <FakeClass>
            {
                FakeClass.CreateItem(),
                FakeClass.CreateItem(false, false, false),
                FakeClass.CreateItem(false, false, true)
            };

            var parser = serviceProvider.GetService <WorksheetParser <FakeClass> >();

            expectedItens.ForEach(x => x.Bonus *= 0.1M);
            var validationResult = new ValidationResult <FakeClass>();
            var error            = new Error("Field TX_NAME can´t not be null", 3, 2);

            validationResult.AddError(error);
            validationResult.AddItem(expectedItens.First());
            validationResult.AddItem(expectedItens.Last());

            var headers = new MyWorksheetMap().GetFields().Select(s => s.Name).ToList();

            using var worksheet = CreateStream(expectedItens, headers);
            var itens = parser.Parse(worksheet, worksheetName);

            using var streamWithErros = parser.WriteErrorsWithSummary(worksheet, worksheetName, itens.Errors);

            using var workbookWithErrors = new XLWorkbook(streamWithErros);
            var reader = new ClosedXmlReader(workbookWithErrors, worksheetName);

            reader.CountColumns().Should().Be(headers.Count() + 1);
        }
        public void ShouldParseItens()
        {
            var itens = new List <FakeClass>
            {
                FakeClass.CreateItem(),
                FakeClass.CreateItem(true),
                FakeClass.CreateItem(),
                FakeClass.CreateItem(true, true),
                FakeClass.CreateItem(),
                FakeClass.CreateItem(false, true),
            };

            var worksheet = new MyWorksheet(itens);
            var parser    = new WorksheetInterpreter <FakeClass>(new ValueSetter(new Converter()), new MyWorksheetMap(), new MessageErrors());
            var rowsFake  = parser.Parse(worksheet);

            itens.ForEach(i => i.Bonus = i.Bonus * 0.1M);
            var validationResult = new ValidationResult <FakeClass>();

            validationResult.AddItem(itens);

            rowsFake.Should().BeEquivalentTo(validationResult);
        }