예제 #1
0
        public void CategoryCRUDTest()
        {
            var context = new NoodleDbContext("NoodleDb");

            ICategoryService service = new CategoryTreeService(context);

            var id = Guid.NewGuid();

            var record = new Category
            {
                Id   = id,
                Key  = "Key_" + id.ToString(),
                Name = "Name_" + id.ToString()
            };

            service.Create(record);

            record.Key  = "U_" + record.Key;
            record.Name = "U_" + record.Name;

            service.Update(record);

            var record2 = service.GetById(id);

            Assert.AreEqual(record.Id, record2.Id);
            Assert.AreEqual(record.Key, record2.Key);
            Assert.AreEqual(record.Name, record2.Name);

            service.Delete(record.Id);

            var record3 = service.GetById(id);

            Assert.IsNull(record3);
        }
예제 #2
0
 private void SetupCategoryTreeService()
 {
     CategoryTreeService = new CategoryTreeService(new CategoryNameServiceSettings()
     {
         CategoriesFilePath = "./queries_functional_test_categories.xml",
         SchemaFilePath     = "./_Categories-xml-data/categories.xsd"
     });
     CategoryTreeService.Init();
 }
예제 #3
0
        public void Init_when_invalid_categories_checks_xsd_and_throws(string testFileName)
        {
            var service = new CategoryTreeService(new CategoryNameServiceSettings()
            {
                CategoriesFilePath = testFileName,
                SchemaFilePath     = "_Categories-xml-data/categories.xsd"
            });

            Assert.Throws <XmlSchemaValidationException>(() => service.Init());
        }
예제 #4
0
        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");
        }
예제 #5
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)
            };
        }
예제 #6
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();
        }
예제 #7
0
 public void SetUp()
 {
     _categoryTreeService    = TestDepedencies.Instance.Value.CategoryTreeService;
     _dbContext              = TestDepedencies.Instance.Value.DbContext;
     _byCategoryQueryHandler = new AuctionsByCategoryQueryHandler(_dbContext, new CategoryBuilder(_categoryTreeService));
 }