示例#1
0
        public void TestGetSupplierByIdReturnsNullFail()
        {
            Models.Response.Supplier fakesupplierResponse = this.GetFakeSupplierResponseModel();

            this.MockGetAllSuppliersResponseTables(false);

            var result = supplierRepositoryMock.GetById(5).Result;

            Assert.IsNull(result.Result);
        }
示例#2
0
        public void TestGetSupplierByIdReturnsSupplierSuccess()
        {
            Models.Response.Supplier fakesupplierResponse = this.GetFakeSupplierResponseModel();

            this.MockGetAllSuppliersResponseTables(true);

            var result = supplierRepositoryMock.GetById(1).Result;

            Assert.IsNotNull(result.Result);
            Assert.IsTrue(result.Result.MGSupplier != null);
        }
示例#3
0
        private Models.Response.Supplier GetFakeSupplierResponseModel()
        {
            Models.Response.Supplier fakeSupplierResponseModel = new Models.Response.Supplier()
            {
                MGSupplier = new Suppliers
                {
                    Id               = 1,
                    Name             = "GTA",
                    NameItemId       = 1,
                    CountryId        = 5,
                    CityId           = 5,
                    BranchName       = "B Name",
                    AddressLine1     = "Society",
                    AddressLine2     = "LandMark",
                    ZipCode          = "ZIP4321",
                    Code             = "ELEIN",
                    Website          = "www.GTA.com",
                    Remark           = "GTA Remark Testing",
                    InternalRemark   = "GTA Internal Remark Testing",
                    RefreshRate      = 5,
                    MGPreferredOrder = 5,
                    ThrottleLimit    = 5,
                    IsMappedWithMG   = true,
                    IsActive         = true,
                    IsDeleted        = false,
                    CreatedBy        = "sa",
                    UpdatedBy        = "sa"
                },

                SupplierContacts = new List <Contacts>
                {
                    new Contacts {
                        SupplierId = 1, DesignationId = 1, ContactPerson = "Jon Doe", EmailAddress = "*****@*****.**", PhoneNumber = "1234567890", IsActive = true,
                        IsDeleted  = false, IsPrimary = true, CreatedBy = "sa", UpdatedBy = "sa"
                    }
                },

                SupplierPayment = new Payment
                {
                    SupplierId         = 1,
                    PaymentTypeId      = 1,
                    CurrencyId         = 1,
                    CreditDays         = 30,
                    WithHoldingTaxId   = 3,
                    WithHoldingTaxRate = "345",
                    IsActive           = true,
                    IsDeleted          = false,
                    CreatedBy          = "sa",
                    UpdatedBy          = "sa"
                },

                Banks = new List <Bank>
                {
                    new Bank {
                        SupplierId = 1, Name = "Oriental", AccountTypeId = 4, Account = "Test Account", Branch = "Test Branch", AccountNumber = "ABC54321", IsPrimarySet = true,
                        IsActive   = true, IsDeleted = false, CreatedBy = "sa", UpdatedBy = "sa"
                    }
                },

                SupplierCredentials = new List <UserRelation>
                {
                    new UserRelation {
                        SupplierId = 1, EnvironmentId = 1, UserInfo = "String Value", IsDeleted = false
                    }
                },

                FunctionEndpoints = new List <Models.Response.FunctionSupplierRelationModel>
                {
                    new Models.Response.FunctionSupplierRelationModel {
                        FunctionId = 1, SupplierId = 1, EnvironmentId = 1, EndpointURL = "https://api.test.hotelbeds.com/hotel-api/1.0/hotels", IsDeleted = false,
                        CreatedBy  = "sa", UpdatedBy = "sa"
                    }
                }
            };

            return(fakeSupplierResponseModel);
        }
示例#4
0
        //[Test]
        //public void TestUpdateSupplierReturnsSuccess()
        //{
        //    SupplierRequestModel fakeSupplierRequest = this.GetFakeSupplierRequestModel();

        //    iSupplierMock.Setup(x => x.ExecuteStoredProcedureInsertUpdate(It.IsAny<string>(), It.IsAny<DynamicParameters>())).Returns(Task.FromResult(new BaseResult<bool>() { Result = true }));

        //    var result = supplierRepositoryMock.UpdateSupplier(fakeSupplierRequest, true, false).Result;

        //    Assert.IsTrue(result.Result);
        //}

        //[Test]
        //public void TestUpdateSupplierReturnsSupplierContactsCountIsZeroSuccess()
        //{
        //    SupplierRequestModel fakeSupplierRequest = this.GetFakeSupplierRequestModel();
        //    fakeSupplierRequest.SupplierContacts = new List<Contacts> { };

        //    iSupplierMock.Setup(x => x.ExecuteStoredProcedureInsertUpdate(It.IsAny<string>(), It.IsAny<DynamicParameters>())).Returns(Task.FromResult(new BaseResult<bool>() { Result = true }));

        //    var result = supplierRepositoryMock.UpdateSupplier(fakeSupplierRequest, true, false).Result;

        //    Assert.IsTrue(result.Result is true);
        //}

        //[Test]
        //public void TestUpdateSupplierReturnsSupplierBanksCountIsZeroSuccess()
        //{
        //    SupplierRequestModel fakeSupplierRequest = this.GetFakeSupplierRequestModel();
        //    fakeSupplierRequest.Banks = new List<Bank> { };

        //    iSupplierMock.Setup(x => x.ExecuteStoredProcedureInsertUpdate(It.IsAny<string>(), It.IsAny<DynamicParameters>())).Returns(Task.FromResult(new BaseResult<bool>() { Result = true }));

        //    var result = supplierRepositoryMock.UpdateSupplier(fakeSupplierRequest, true, false).Result;

        //    Assert.IsTrue(result.Result is true);
        //}

        //[Test]
        //public void TestDeleteSupplierReturnsSuccess()
        //{
        //    SupplierRequestModel fakeSupplierRequest = this.GetFakeSupplierRequestModel();

        //    iSupplierMock.Setup(x => x.UpdateEntityByDapper(fakeSupplierRequest.Supplier)).Returns(Task.FromResult(new BaseResult<bool>() { Result = true }));

        //    var result = supplierRepositoryMock.UpdateSupplier(fakeSupplierRequest, false, true).Result;

        //    Assert.IsTrue(result.Result);
        //}



        private void MockGetAllSuppliersResponseTables(bool ifSuccess)
        {
            Models.Response.Supplier        fakeSupplierResponse     = this.GetFakeSupplierResponseModel();
            List <Models.Response.Supplier> fakeListSupplierResponse = this.GetFakeListOfSupplierResponseModel();

            var supplierList = new List <Suppliers>();

            foreach (var supplier in fakeListSupplierResponse)
            {
                supplierList.Add(supplier.MGSupplier);
            }

            var supplierContacts = new Contacts
            {
                SupplierId    = 1,
                DesignationId = 1,
                ContactPerson = "Jon Doe",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "1234567890",
                IsActive      = true,
                IsDeleted     = false,
                IsPrimary     = true,
                CreatedBy     = "sa",
                UpdatedBy     = "sa"
            };

            var supplierBank = new Bank
            {
                SupplierId    = 1,
                Name          = "Oriental",
                AccountTypeId = 4,
                Account       = "Test Account",
                Branch        = "Test Branch",
                AccountNumber = "ABC54321",
                IsPrimarySet  = true,
                IsActive      = true,
                IsDeleted     = false,
                CreatedBy     = "sa",
                UpdatedBy     = "sa"
            };

            var supplierCredentials = new UserRelation
            {
                SupplierId    = 1,
                EnvironmentId = 1,
                UserInfo      = "String Value",
                IsDeleted     = false
            };

            var functionEndpoints = new FunctionSupplierRelation
            {
                FunctionId    = 1,
                SupplierId    = 1,
                EnvironmentId = 1,
                EndpointURL   = "https://api.test.hotelbeds.com/hotel-api/1.0/hotels",
                IsDeleted     = false,
                CreatedBy     = "sa",
                UpdatedBy     = "sa"
            };



            var supplierPred = new Func <Suppliers, bool>(x => x.IsActive && !x.IsDeleted);

            if (ifSuccess)
            {
                iSupplierMock.Setup(x => x.GetListByPredicate(It.Is <Func <Suppliers, bool> >(a => a.GetType() == supplierPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <Suppliers> > {
                    Result = new List <Suppliers>()
                    {
                        fakeSupplierResponse.MGSupplier
                    }, IsError = false
                }));
            }
            else
            {
                iSupplierMock.Setup(x => x.GetListByPredicate(It.Is <Func <Suppliers, bool> >(a => a.GetType() == supplierPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <Suppliers> > {
                    Result = new List <Suppliers>(), IsError = false
                }));
            }

            var supplierContactsPred = new Func <Contacts, bool>(a => a.IsActive && !a.IsDeleted && a.SupplierId == fakeSupplierResponse.MGSupplier.Id);

            iSupplierContactsMock.Setup(x => x.GetListByPredicate(It.Is <Func <Contacts, bool> >(a => a.GetType() == supplierContactsPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <Contacts> > {
                Result = new List <Contacts>()
                {
                    supplierContacts
                }, IsError = false
            }));

            var supplierBankPred = new Func <Bank, bool>((a => !a.IsDeleted && a.SupplierId == fakeSupplierResponse.MGSupplier.Id));

            iSupplierBankMock.Setup(x => x.GetListByPredicate(It.Is <Func <Bank, bool> >(a => a.GetType() == supplierBankPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <Bank> > {
                Result = new List <Bank>()
                {
                    supplierBank
                }, IsError = false
            }));

            var supplierPaymentPred = new Func <Payment, bool>((a => !a.IsDeleted && a.SupplierId == fakeSupplierResponse.MGSupplier.Id));

            iSupplierPaymentMock.Setup(x => x.GetListByPredicate(It.Is <Func <Payment, bool> >(a => a.GetType() == supplierPaymentPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <Payment> > {
                Result = new List <Payment>()
                {
                    fakeSupplierResponse.SupplierPayment
                }, IsError = false
            }));

            var supplierCredentialsPred = new Func <UserRelation, bool>(a => !a.IsDeleted && a.SupplierId == fakeSupplierResponse.MGSupplier.Id);

            iSupplierUserRelationMock.Setup(x => x.GetListByPredicate(It.Is <Func <UserRelation, bool> >(a => a.GetType() == supplierCredentialsPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <UserRelation> > {
                Result = new List <UserRelation>()
                {
                    supplierCredentials
                }, IsError = false
            }));

            var supplierFunctionEndpointsPred = new Func <FunctionSupplierRelation, bool>(a => !a.IsDeleted && a.SupplierId == fakeSupplierResponse.MGSupplier.Id);

            iSupplierFunctionMock.Setup(x => x.GetListByPredicate(It.Is <Func <FunctionSupplierRelation, bool> >(a => a.GetType() == supplierFunctionEndpointsPred.GetType()))).Returns(Task.FromResult(new BaseResult <List <FunctionSupplierRelation> > {
                Result = new List <FunctionSupplierRelation>()
                {
                    functionEndpoints
                }, IsError = false
            }));
        }