Beispiel #1
0
        public void Setup()
        {
            #region Companies
            var masterCompany = new Entities.Company
            {
                Id     = 1,
                Name   = "Master Company",
                Parent = null
            };

            var firstChildOfMaster = new Entities.Company
            {
                Id     = 2,
                Name   = "First Child of Master Company",
                Parent = masterCompany
            };

            var secondChildOfMaster = new Entities.Company
            {
                Id     = 3,
                Name   = "Second Child of Master Company",
                Parent = masterCompany
            };

            masterCompany.MyCompanies = new List <Entities.Company> {
                firstChildOfMaster, secondChildOfMaster
            };

            var firstChildsFirstChild = new Entities.Company
            {
                Id     = 4,
                Name   = "First Child's First Child",
                Parent = firstChildOfMaster
            };

            var firstChildsSecondChild = new Entities.Company
            {
                Id     = 5,
                Name   = "First Child's Second Child",
                Parent = firstChildOfMaster
            };

            firstChildOfMaster.MyCompanies = new List <Entities.Company> {
                firstChildsFirstChild, firstChildsSecondChild
            };

            #endregion

            #region Catalogs
            var defaultCatalog = new Entities.Catalog.Catalog
            {
                Id   = 1,
                Name = "Default Catalog",
            };

            var masterAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 2,
                Name = "Master's Assignable Catalog",
            };

            var firstChildsFirstAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 3,
                Name = "First Child's First Assignable Catalog",
            };

            var firstChildsSecondAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 4,
                Name = "First Child's Second Assignable Catalog",
            };

            var secondChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 5,
                Name = "Second Child's Assignable Catalog",
            };

            var firstChildsFirstChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 6,
                Name = "First Child's First Child's Assignable Catalog",
            };

            var firstChildsSecondChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 7,
                Name = "First Child's Second Child's Assignable Catalog",
            };
            #endregion

            #region Company Catalogs
            masterCompany.CompanyCatalogs = new List <CompanyCatalog>
            {
                new CompanyCatalog
                {
                    Catalog     = defaultCatalog,
                    CatalogId   = 1,
                    CatalogType = CatalogType.Assigned,
                },
                new CompanyCatalog
                {
                    Catalog     = masterAssignableCatalog,
                    CatalogId   = 2,
                    CatalogType = CatalogType.MyCatalog,
                }
            };

            firstChildOfMaster.CompanyCatalogs = new List <CompanyCatalog>
            {
                new CompanyCatalog
                {
                    Catalog     = defaultCatalog,
                    CatalogId   = 1,
                    CatalogType = CatalogType.Assigned,
                },
                new CompanyCatalog
                {
                    Catalog     = firstChildsFirstAssignableCatalog,
                    CatalogId   = 3,
                    CatalogType = CatalogType.MyCatalog,
                },
                new CompanyCatalog
                {
                    Catalog     = firstChildsSecondAssignableCatalog,
                    CatalogId   = 4,
                    CatalogType = CatalogType.MyCatalog,
                }
            };

            secondChildOfMaster.CompanyCatalogs = new List <CompanyCatalog>
            {
                new CompanyCatalog
                {
                    Catalog     = masterAssignableCatalog,
                    CatalogId   = 2,
                    CatalogType = CatalogType.Assigned,
                },
                new CompanyCatalog
                {
                    Catalog     = secondChildsAssignableCatalog,
                    CatalogId   = 5,
                    CatalogType = CatalogType.MyCatalog,
                },
            };

            firstChildsFirstChild.CompanyCatalogs = new List <CompanyCatalog>
            {
                new CompanyCatalog
                {
                    Catalog     = firstChildsFirstAssignableCatalog,
                    CatalogId   = 3,
                    CatalogType = CatalogType.MyCatalog,
                },
                new CompanyCatalog
                {
                    Catalog     = firstChildsFirstChildsAssignableCatalog,
                    CatalogId   = 6,
                    CatalogType = CatalogType.MyCatalog,
                },
            };
            firstChildsSecondChild.CompanyCatalogs = new List <CompanyCatalog>
            {
                new CompanyCatalog
                {
                    Catalog     = firstChildsFirstAssignableCatalog,
                    CatalogId   = 3,
                    CatalogType = CatalogType.Assigned,
                },
                new CompanyCatalog
                {
                    Catalog     = firstChildsSecondChildsAssignableCatalog,
                    CatalogId   = 7,
                    CatalogType = CatalogType.MyCatalog,
                },
            };

            #endregion

            var companies = new List <Entities.Company>
            {
                masterCompany,
                firstChildOfMaster,
                firstChildsFirstChild,
                firstChildsSecondChild,
                secondChildOfMaster,
            };

            var companiesDbSet = MockSetGenerator.CreateAsyncMockSet(companies);
            var dbContextMock  = new Mock <CldpDbContext>();
            dbContextMock.Setup(c => c.Companies).Returns(companiesDbSet);

            var catalogUtilitiesMock = new Mock <ICatalogUtilities>();

            var catalogProductItemServiceMock = new Mock <ICatalogProductItemService>();

            _sut = new Database.Catalog.CompanyCatalogService(dbContextMock.Object, catalogProductItemServiceMock.Object, catalogUtilitiesMock.Object);
        }
Beispiel #2
0
        public void Setup()
        {
            #region Companies
            var masterCompany = new Entities.Company
            {
                Id     = 1,
                Name   = "Master Company",
                Parent = null
            };

            var firstChildOfMaster = new Entities.Company
            {
                Id     = 2,
                Name   = "First Child of Master Company",
                Parent = masterCompany
            };

            var secondChildOfMaster = new Entities.Company
            {
                Id     = 3,
                Name   = "Second Child of Master Company",
                Parent = masterCompany
            };

            masterCompany.MyCompanies = new List <Entities.Company> {
                firstChildOfMaster, secondChildOfMaster
            };

            var firstChildsFirstChild = new Entities.Company
            {
                Id     = 4,
                Name   = "First Child's First Child",
                Parent = firstChildOfMaster
            };

            var firstChildsSecondChild = new Entities.Company
            {
                Id     = 5,
                Name   = "First Child's Second Child",
                Parent = firstChildOfMaster
            };

            firstChildOfMaster.MyCompanies = new List <Entities.Company> {
                firstChildsFirstChild, firstChildsSecondChild
            };

            #endregion

            #region Catalogs
            var defaultCatalog = new Entities.Catalog.Catalog
            {
                Id   = 1,
                Name = "Default Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var masterFirstAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 2,
                Name = "Master's First Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 11,
                        ResellerPrice    = 6,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 11,
                        ResellerPrice    = 6,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 11,
                        ResellerPrice    = 6,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 11,
                        ResellerPrice    = 6,
                    }
                }
            };

            var masterSecondAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 8,
                Name = "Master's Second Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = false,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = false,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var firstChildsFirstAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 3,
                Name = "First Child's First Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var firstChildsSecondAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 4,
                Name = "First Child's Second Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var secondChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 5,
                Name = "Second Child's Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var firstChildsFirstChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 6,
                Name = "First Child's First Child's Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };

            var firstChildsSecondChildsAssignableCatalog = new Entities.Catalog.Catalog
            {
                Id   = 7,
                Name = "First Child's Second Child's Assignable Catalog",
                CatalogProductItems = new List <CatalogProductItem>
                {
                    new CatalogProductItem
                    {
                        ProductItemId    = 1,
                        Available        = true,
                        FixedRetailPrice = true,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 2,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 3,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    },
                    new CatalogProductItem
                    {
                        ProductItemId    = 4,
                        Available        = true,
                        FixedRetailPrice = false,
                        RetailPrice      = 10,
                        ResellerPrice    = 5,
                    }
                }
            };
            #endregion

            #region Company Catalogs

            var masterAssigned = new CompanyCatalog
            {
                Catalog     = defaultCatalog,
                CatalogId   = 1,
                Company     = masterCompany,
                CatalogType = CatalogType.Assigned,
            };
            var masterFirstAssignable = new CompanyCatalog
            {
                Catalog     = masterFirstAssignableCatalog,
                CatalogId   = 2,
                Company     = masterCompany,
                CatalogType = CatalogType.MyCatalog
            };
            var masterSecondAssignable = new CompanyCatalog
            {
                Catalog     = masterSecondAssignableCatalog,
                CatalogId   = 8,
                Company     = masterCompany,
                CatalogType = CatalogType.MyCatalog
            };
            masterCompany.CompanyCatalogs = new List <CompanyCatalog>
            {
                masterAssigned,
                masterFirstAssignable,
                masterSecondAssignable
            };

            var firstChildOfMasterAssigned = new CompanyCatalog
            {
                Catalog     = defaultCatalog,
                CatalogId   = 1,
                Company     = firstChildOfMaster,
                CatalogType = CatalogType.Assigned
            };
            var firstChildOfMasterFirstAssignable = new CompanyCatalog
            {
                Catalog     = firstChildsFirstAssignableCatalog,
                CatalogId   = 3,
                Company     = firstChildOfMaster,
                CatalogType = CatalogType.MyCatalog
            };
            var firstChildOfMasterSecondAssignable = new CompanyCatalog
            {
                Catalog     = firstChildsSecondAssignableCatalog,
                CatalogId   = 4,
                Company     = firstChildOfMaster,
                CatalogType = CatalogType.MyCatalog
            };
            firstChildOfMaster.CompanyCatalogs = new List <CompanyCatalog>
            {
                firstChildOfMasterAssigned,
                firstChildOfMasterFirstAssignable,
                firstChildOfMasterSecondAssignable
            };

            var secondChildOfMasterAssigned = new CompanyCatalog
            {
                Catalog     = masterFirstAssignableCatalog,
                CatalogId   = 2,
                Company     = secondChildOfMaster,
                CatalogType = CatalogType.Assigned
            };
            var secondChildOfMasterAssignable = new CompanyCatalog
            {
                Catalog     = secondChildsAssignableCatalog,
                CatalogId   = 5,
                Company     = secondChildOfMaster,
                CatalogType = CatalogType.MyCatalog
            };
            secondChildOfMaster.CompanyCatalogs = new List <CompanyCatalog>
            {
                secondChildOfMasterAssigned,
                secondChildOfMasterAssignable
            };

            var firstChildsFirstChildAssigned = new CompanyCatalog
            {
                Catalog     = firstChildsFirstAssignableCatalog,
                CatalogId   = 3,
                Company     = firstChildsFirstChild,
                CatalogType = CatalogType.Assigned
            };
            var firstChildsFirstChildAssignable = new CompanyCatalog
            {
                Catalog     = firstChildsFirstChildsAssignableCatalog,
                CatalogId   = 6,
                Company     = firstChildsFirstChild,
                CatalogType = CatalogType.MyCatalog,
            };
            firstChildsFirstChild.CompanyCatalogs = new List <CompanyCatalog>
            {
                firstChildsFirstChildAssigned,
                firstChildsFirstChildAssignable
            };

            var firstChildsSecondChildAssigned = new CompanyCatalog
            {
                Catalog     = firstChildsSecondAssignableCatalog,
                CatalogId   = 4,
                Company     = firstChildsSecondChild,
                CatalogType = CatalogType.Assigned
            };
            var firstChildsSecondsChildAssignable = new CompanyCatalog
            {
                Catalog     = firstChildsSecondChildsAssignableCatalog,
                CatalogId   = 7,
                Company     = firstChildsSecondChild,
                CatalogType = CatalogType.MyCatalog
            };
            firstChildsSecondChild.CompanyCatalogs = new List <CompanyCatalog>
            {
                firstChildsSecondChildAssigned,
                firstChildsSecondsChildAssignable
            };

            #endregion

            var companies = new List <Entities.Company>
            {
                masterCompany,
                firstChildOfMaster,
                firstChildsFirstChild,
                firstChildsSecondChild,
                secondChildOfMaster
            };

            var companyCatalogs = new List <CompanyCatalog>
            {
                masterAssigned,
                masterFirstAssignable,
                masterSecondAssignable,
                firstChildOfMasterAssigned,
                firstChildOfMasterFirstAssignable,
                firstChildOfMasterSecondAssignable,
                secondChildOfMasterAssigned,
                secondChildOfMasterAssignable,
                firstChildsFirstChildAssigned,
                firstChildsFirstChildAssignable,
                firstChildsSecondChildAssigned,
                firstChildsSecondsChildAssignable
            };

            _companiesDbSet       = MockSetGenerator.CreateAsyncMockSet(companies);
            _companyCatalogsDbSet = MockSetGenerator.CreateAsyncMockSet(companyCatalogs);

            _dbContextMock = new Mock <CldpDbContext>();
            _dbContextMock.Setup(c => c.Companies).Returns(_companiesDbSet);
            _dbContextMock.Setup(c => c.CompanyCatalogs).Returns(_companyCatalogsDbSet);

            var catalogUtilitiesMock = new Mock <ICatalogUtilities>();

            _catalogProductItemServiceMock = new Mock <ICatalogProductItemService>();
            _catalogProductItemServiceMock.Setup(c => c.AddProductItemToCatalog(It.IsAny <CatalogProductModel>())).Returns(Task.CompletedTask);
            _catalogProductItemServiceMock.Setup(c => c.RemoveProductItemFromCatalog(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.CompletedTask);
            _catalogProductItemServiceMock.Setup(c => c.UpdateFixedRetailPrice(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>())).Returns(Task.CompletedTask);

            _sut = new Database.Catalog.CompanyCatalogService(_dbContextMock.Object, _catalogProductItemServiceMock.Object, catalogUtilitiesMock.Object);
        }