public async Task Should_Validate_Double_Data() { var facade = new GarmentInvoiceFacade(_dbContext(GetCurrentMethod()), ServiceProvider); GarmentInvoice model = await dataUtil(facade, GetCurrentMethod()).GetTestData(USERNAME); GarmentInvoiceViewModel viewModel = new GarmentInvoiceViewModel { supplier = new SupplierViewModel(), }; viewModel.Id = model.Id + 1; viewModel.invoiceNo = model.InvoiceNo; viewModel.supplier.Id = model.SupplierId; viewModel.invoiceDate = model.InvoiceDate; Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); serviceProvider. Setup(x => x.GetService(typeof(PurchasingDbContext))) .Returns(_dbContext(GetCurrentMethod())); ValidationContext validationContext = new ValidationContext(viewModel, serviceProvider.Object, null); var validationResultCreate = viewModel.Validate(validationContext).ToList(); var errorDuplicate = validationResultCreate.SingleOrDefault(r => r.ErrorMessage.Equals("No is already exist")); Assert.NotNull(errorDuplicate); }
public void Should_Success_Validate_Data() { GarmentInvoiceViewModel nullViewModel = new GarmentInvoiceViewModel(); Assert.True(nullViewModel.Validate(null).Count() > 0); var tomorrow = DateTime.Now.Date.AddDays(+1); GarmentInvoiceViewModel viewModel = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = tomorrow, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "name", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, hasInternNote = false, currency = { }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = new List <GarmentInvoiceDetailViewModel> { new GarmentInvoiceDetailViewModel { doQuantity = 0 } } } } }; Assert.True(viewModel.Validate(null).Count() > 0); GarmentInvoiceViewModel viewModels = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = DateTimeOffset.MinValue, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "name", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, hasInternNote = false, currency = new CurrencyViewModel { Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = "" }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = null } } }; Assert.True(viewModels.Validate(null).Count() > 0); GarmentInvoiceViewModel viewModels1 = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = DateTimeOffset.MinValue, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, poSerialNumber = "any", hasInternNote = false, currency = new CurrencyViewModel { Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = "" }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = null } } }; Assert.True(viewModels1.Validate(null).Count() > 0); }
public void Should_Success_Validate_Data() { Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); serviceProvider.Setup(x => x.GetService(typeof(PurchasingDbContext))) .Returns(_dbContext(GetCurrentMethod())); GarmentInvoiceViewModel nullViewModel = new GarmentInvoiceViewModel(); Assert.True(nullViewModel.Validate(null).Count() > 0); var tomorrow = DateTime.Now.Date.AddDays(+1); GarmentInvoiceViewModel viewModel = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = tomorrow, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "name", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatId = It.IsAny <int>(), vatRate = 10, vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, hasInternNote = false, currency = { }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = new List <GarmentInvoiceDetailViewModel> { new GarmentInvoiceDetailViewModel { doQuantity = 0 } } } } }; System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate1 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModel, serviceProvider.Object, null); Assert.True(viewModel.Validate(garmentInvoiceValidate1).Count() > 0); GarmentInvoiceViewModel viewModels = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = DateTimeOffset.MinValue, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "name", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatId = It.IsAny <int>(), vatRate = 10, vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, hasInternNote = false, currency = new CurrencyViewModel { Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = "" }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = null } } }; System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate11 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels, serviceProvider.Object, null); Assert.True(viewModels.Validate(garmentInvoiceValidate11).Count() > 0); GarmentInvoiceViewModel viewModels1 = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = DateTimeOffset.MinValue, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatId = It.IsAny <int>(), vatRate = 10, vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, poSerialNumber = "any", hasInternNote = false, currency = new CurrencyViewModel { Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = "" }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = null, details = null } } }; System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate12 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels1, serviceProvider.Object, null); Assert.True(viewModels1.Validate(garmentInvoiceValidate12).Count() > 0); GarmentInvoiceViewModel viewModels12 = new GarmentInvoiceViewModel { invoiceNo = "", invoiceDate = DateTimeOffset.MinValue, supplier = { }, incomeTaxId = It.IsAny <int>(), incomeTaxName = "", incomeTaxNo = "", incomeTaxDate = DateTimeOffset.MinValue, incomeTaxRate = 2, vatNo = "", vatId = It.IsAny <int>(), vatRate = 10, vatDate = DateTimeOffset.MinValue, useIncomeTax = true, useVat = true, isPayTax = true, poSerialNumber = "any", hasInternNote = false, currency = new CurrencyViewModel { Id = It.IsAny <int>(), Code = "USD", Symbol = "$", Rate = 13000, Description = "" }, items = new List <GarmentInvoiceItemViewModel> { new GarmentInvoiceItemViewModel { deliveryOrder = new GarmentDeliveryOrderViewModel { doNo = "test1", arrivalDate = tomorrow, doDate = tomorrow }, details = null }, new GarmentInvoiceItemViewModel { deliveryOrder = new GarmentDeliveryOrderViewModel { doNo = "test1", arrivalDate = tomorrow, doDate = tomorrow }, details = null } } }; System.ComponentModel.DataAnnotations.ValidationContext garmentInvoiceValidate13 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModels12, serviceProvider.Object, null); Assert.True(viewModels12.Validate(garmentInvoiceValidate13).Count() > 0); }