コード例 #1
0
        private AuctionRead[] GetFakeAuctionsReadModels()
        {
            var testCategoryTree = _categoryTreeService.GetCategoriesTree();
            var testCategory     = new Category(testCategoryTree.SubCategories[0]
                                                .CategoryName, 0);

            testCategory.SubCategory = new Category(testCategoryTree.SubCategories[0]
                                                    .SubCategories[0]
                                                    .CategoryName, 1);
            testCategory.SubCategory.SubCategory = new Category(testCategoryTree.SubCategories[0]
                                                                .SubCategories[0]
                                                                .SubCategories[0]
                                                                .CategoryName, 2);

            var auctions = new AuctionRead[AuctionsByCategoryQueryHandler.PageSize * 2];

            for (var i = 0; i < auctions.Length; i++)
            {
                auctions[i] = new AuctionRead()
                {
                    ActualPrice = 20,
                    AuctionId   = Guid.NewGuid()
                                  .ToString(),
                    BuyNowPrice = 21,
                    StartDate   = DateTime.UtcNow,
                    EndDate     = DateTime.UtcNow.AddDays(1),
                    Category    = testCategory,
                    BuyNowOnly  = false,
                    Product     = new Product("test product name", "example description", Condition.Used)
                };
            }

            return(auctions);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: pekalam/auctionhouse
        public async Task ApiCreateAuction_when_session_started_creates_auction()
        {
            var fixture = new Fixture();

            var categoryTreeService = new CategoryTreeService(new CategoryNameServiceSettings()
            {
                CategoriesFilePath = "_Categories-xml-data/categories.xml",
                SchemaFilePath     = "_Categories-xml-data/categories.xsd"
            });

            categoryTreeService.Init();
            List <string> categories = new List <string>()
            {
                categoryTreeService.GetCategoriesTree().SubCategories[0].CategoryName,
                          categoryTreeService.GetCategoriesTree().SubCategories[0].SubCategories[1].CategoryName,
                          categoryTreeService.GetCategoriesTree().SubCategories[0].SubCategories[1].SubCategories[2].CategoryName,
            };


            CreateAuctionCommandDto createAuctionCmd = fixture.Build <CreateAuctionCommandDto>()
                                                       .With(dto => dto.Category, categories)
                                                       .With(dto => dto.StartDate, DateTime.UtcNow)
                                                       .With(dto => dto.EndDate, DateTime.UtcNow.AddMonths(1))
                                                       .With(dto => dto.Tags, new[] { "tag1", "tag2" })
                                                       .Create();

            var startSessionReq = new HttpRequestMessage(HttpMethod.Post, "/api/startCreateSession")
                                  .AddUserAuthHeader(_factory);
            var startSessionResponse = await client.SendAsync(startSessionReq);

            startSessionResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            var req = new HttpRequestMessage(HttpMethod.Post, "/api/createAuction")
                      .AddUserAuthHeader(_factory)
                      .AddJsonBody(createAuctionCmd);
            var response = await client.SendAsync(req);


            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var requestStatus = await response.GetRequestStatus();

            requestStatus.CorrelationId.Should().NotBeEmpty();
            requestStatus.Status.Should().Be("COMPLETED");
        }
コード例 #3
0
        public void SetUp()
        {
            _categoryTreeService = TestDepedencies.Instance.Value.CategoryTreeService;
            _dbContext           = TestDepedencies.Instance.Value.DbContext;
            var testCategoryTree = _categoryTreeService.GetCategoriesTree();
            var testCategory     = new Category(testCategoryTree.SubCategories[0].CategoryName, 0);

            testCategory.SubCategory             = new Category(testCategoryTree.SubCategories[0].SubCategories[0].CategoryName, 1);
            testCategory.SubCategory.SubCategory = new Category(testCategoryTree.SubCategories[0].SubCategories[0].SubCategories[0].CategoryName, 2);
            stubAuction = new AuctionRead()
            {
                ActualPrice = 20,
                AuctionId   = Guid.NewGuid().ToString(),
                BuyNowPrice = 21,
                StartDate   = DateTime.UtcNow.AddMinutes(12),
                EndDate     = DateTime.UtcNow.AddDays(1),
                Category    = testCategory,
                Product     = new Product("test product name", "example description", Condition.New)
            };
        }
コード例 #4
0
        public void GetCategoryTree_when_called_returns_valid_category_tree()
        {
            var serviceSettings = new CategoryNameServiceSettings()
            {
                CategoriesFilePath = "./test_categories.xml",
                SchemaFilePath     = "_Categories-xml-data/categories.xsd"
            };
            var testService = new CategoryTreeService(serviceSettings);

            testService.Init();

            var categories         = new[] { "Fashion", "Electronics", "Sports, Hobbies & Leisure" };
            var subCategoriesCount = new[] { 11, 8, 8 };
            var categoryIds        = new[] { 0, 1, 2 };
            var root = testService.GetCategoriesTree();

            for (int i = 0; i < root.SubCategories.Count; i++)
            {
                var category = root.SubCategories[i];

                category.CategoryId.Should().Be(categoryIds[i]);
                category.CategoryName.Should().Be(categories[i]);
                category.SubCategories.Count.Should().Be(subCategoriesCount[i]);
                for (int j = 0; j < category.SubCategories.Count; j++)
                {
                    var subCategory = category.SubCategories[j];
                    subCategory.CategoryName.Should().NotBeNullOrEmpty();
                    subCategory.SubCategories.Count.Should().Be(2);
                    for (int k = 0; k < subCategory.SubCategories.Count; k++)
                    {
                        var subSubCat = subCategory.SubCategories[k];
                        subSubCat.CategoryName.Should().NotBeNullOrEmpty();
                    }
                }
            }

            root.SubCategories.Count.Should().Be(3);
            root.CategoryName.Should().BeNull();
        }