public void Should_Success_Validate_Data()
        {
            var viewModelNullItems = new GarmentInternNoteViewModel
            {
                items = null,
            };

            Assert.True(viewModelNullItems.Validate(null).Count() > 0);

            Mock <IGarmentInvoice> garmentInvoiceFacadeMock = new Mock <IGarmentInvoice>();

            garmentInvoiceFacadeMock.Setup(s => s.ReadById(1))
            .Returns(new Lib.Models.GarmentInvoiceModel.GarmentInvoice {
                UseIncomeTax = false, UseVat = false, IncomeTaxId = 1, Items = new List <GarmentInvoiceItem> {
                    new GarmentInvoiceItem
                    {
                        InvoiceId     = 1,
                        PaymentMethod = "PaymentMethod1"
                    }
                }
            });
            garmentInvoiceFacadeMock.Setup(s => s.ReadById(2))
            .Returns(new Lib.Models.GarmentInvoiceModel.GarmentInvoice
            {
                UseIncomeTax = true,
                UseVat       = true,
                IncomeTaxId  = 2,
                Items        = new List <GarmentInvoiceItem> {
                    new GarmentInvoiceItem
                    {
                        InvoiceId     = 2,
                        PaymentMethod = "PaymentMethod2"
                    }
                }
            });

            Mock <IGarmentDeliveryOrderFacade> garmentDeliveryOrderFacadeMock = new Mock <IGarmentDeliveryOrderFacade>();

            garmentDeliveryOrderFacadeMock.Setup(s => s.ReadById(It.IsAny <int>()))
            .Returns(new Lib.Models.GarmentDeliveryOrderModel.GarmentDeliveryOrder());

            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentInvoice)))
            .Returns(garmentInvoiceFacadeMock.Object);
            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentDeliveryOrderFacade)))
            .Returns(garmentDeliveryOrderFacadeMock.Object);

            var sameUseVat = new GarmentInternNoteViewModel
            {
                items = new List <GarmentInternNoteItemViewModel>
                {
                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = new GarmentInvoiceViewModel
                        {
                            Id = 1
                        },
                        details = new List <GarmentInternNoteDetailViewModel>
                        {
                            new GarmentInternNoteDetailViewModel
                            {
                                deliveryOrder = new Lib.ViewModels.GarmentDeliveryOrderViewModel.GarmentDeliveryOrderViewModel
                                {
                                    Id = 1
                                }
                            }
                        }
                    },
                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = new GarmentInvoiceViewModel
                        {
                            Id = 2
                        },
                        details = new List <GarmentInternNoteDetailViewModel>
                        {
                            new GarmentInternNoteDetailViewModel
                            {
                                deliveryOrder = new Lib.ViewModels.GarmentDeliveryOrderViewModel.GarmentDeliveryOrderViewModel
                                {
                                    Id = 2
                                }
                            }
                        }
                    },
                }
            };

            ValidationContext Usevats = new ValidationContext(sameUseVat, serviceProvider.Object, null);

            Assert.True(sameUseVat.Validate(Usevats).Count() > 0);

            var viewModelNullDetail = new GarmentInternNoteViewModel
            {
                items = new List <GarmentInternNoteItemViewModel>
                {
                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = null,
                        details        = null
                    }
                }
            };

            Assert.True(viewModelNullDetail.Validate(null).Count() > 0);
        }
Exemplo n.º 2
0
        public void Should_Success_Validate_Data()
        {
            var viewModelNullItems = new GarmentInternNoteViewModel
            {
                items = null,
            };

            //System.ComponentModel.DataAnnotations.ValidationContext garmentINValidate1 = new System.ComponentModel.DataAnnotations.ValidationContext(viewModelNullItems, serviceProvider.Object, null);
            Assert.True(viewModelNullItems.Validate(null).Count() > 0);

            Mock <IGarmentInvoice> garmentInvoiceFacadeMock = new Mock <IGarmentInvoice>();

            garmentInvoiceFacadeMock.Setup(s => s.ReadById(1))
            .Returns(new Lib.Models.GarmentInvoiceModel.GarmentInvoice {
                UseIncomeTax = false, UseVat = false, IncomeTaxId = 1, Items = new List <GarmentInvoiceItem> {
                    new GarmentInvoiceItem
                    {
                        InvoiceId     = 1,
                        PaymentMethod = "PaymentMethod1"
                    }
                }
            });
            garmentInvoiceFacadeMock.Setup(s => s.ReadById(2))
            .Returns(new Lib.Models.GarmentInvoiceModel.GarmentInvoice
            {
                UseIncomeTax = true,
                UseVat       = true,
                IncomeTaxId  = 2,
                Items        = new List <GarmentInvoiceItem> {
                    new GarmentInvoiceItem
                    {
                        InvoiceId     = 2,
                        PaymentMethod = "PaymentMethod2"
                    }
                }
            });

            Mock <IGarmentDeliveryOrderFacade> garmentDeliveryOrderFacadeMock = new Mock <IGarmentDeliveryOrderFacade>();

            garmentDeliveryOrderFacadeMock.Setup(s => s.ReadById(It.IsAny <int>()))
            .Returns(new Lib.Models.GarmentDeliveryOrderModel.GarmentDeliveryOrder());

            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentInvoice)))
            .Returns(garmentInvoiceFacadeMock.Object);
            serviceProvider.
            Setup(x => x.GetService(typeof(IGarmentDeliveryOrderFacade)))
            .Returns(garmentDeliveryOrderFacadeMock.Object);
            serviceProvider.
            Setup(x => x.GetService(typeof(PurchasingDbContext)))
            .Returns(_dbContext(GetCurrentMethod()));

            //var sameUseVat = new GarmentInternNoteViewModel
            //{
            //    items = new List<GarmentInternNoteItemViewModel>
            //    {
            //        new GarmentInternNoteItemViewModel
            //        {
            //            garmentInvoice  = new GarmentInvoiceViewModel
            //            {
            //                Id = 1
            //            },
            //            details = new List<GarmentInternNoteDetailViewModel>
            //            {
            //                new GarmentInternNoteDetailViewModel
            //                {
            //                    deliveryOrder = new Lib.ViewModels.GarmentDeliveryOrderViewModel.GarmentDeliveryOrderViewModel
            //                    {
            //                        Id = 1
            //                    }
            //                }
            //            }
            //        },
            //        new GarmentInternNoteItemViewModel
            //        {
            //            garmentInvoice  = new GarmentInvoiceViewModel
            //            {
            //                Id = 2
            //            },
            //            details = new List<GarmentInternNoteDetailViewModel>
            //            {
            //                new GarmentInternNoteDetailViewModel
            //                {
            //                     deliveryOrder = new Lib.ViewModels.GarmentDeliveryOrderViewModel.GarmentDeliveryOrderViewModel
            //                    {
            //                        Id = 2
            //                    }
            //                }
            //            }
            //        },

            //    }
            //};
            //ValidationContext Usevats = new ValidationContext(sameUseVat, serviceProvider.Object, null);
            //Assert.True(sameUseVat.Validate(Usevats).Count() > 0);

            var viewModelNullDetail = new GarmentInternNoteViewModel
            {
                items = new List <GarmentInternNoteItemViewModel>
                {
                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = null,
                        details        = null
                    }
                }
            };

            Assert.True(viewModelNullDetail.Validate(null).Count() > 0);

            var date = DateTime.Now;

            var viewModelNullDetail2 = new GarmentInternNoteViewModel
            {
                items = new List <GarmentInternNoteItemViewModel>
                {
                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = new GarmentInvoiceViewModel {
                            Id          = 1,
                            invoiceNo   = "invotest123",
                            invoiceDate = date
                        },
                        details = null
                    },

                    new GarmentInternNoteItemViewModel
                    {
                        garmentInvoice = new GarmentInvoiceViewModel {
                            Id          = 2,
                            invoiceNo   = "invotest123",
                            invoiceDate = date
                        },
                        details = null
                    },
                }
            };
            ValidationContext Usevats = new ValidationContext(viewModelNullDetail2, serviceProvider.Object, null);

            Assert.True(viewModelNullDetail2.Validate(Usevats).Count() > 0);
        }