Beispiel #1
0
        public void AddAsync_IsWebsiteNameUnique_ReturnsNotUniqueException()
        {
            using var context = new DataContext(options);
            var mc = new MemoryCache(new MemoryCacheOptions());
            var categoryService = new CategoryService(context, mc);

            websiteService = new WebsiteService(context, categoryService, new UserService(new PasswordService()));

            Assert.CatchAsync(typeof(NotUniqueException), async() => await websiteService.AddAsync(websiteAddModel), "Should return ArgumentNullException.");
        }
Beispiel #2
0
        public async Task AddAsync_CreatesWebsite()
        {
            using var context = new DataContext(options);
            var mc = new MemoryCache(new MemoryCacheOptions());
            var categoryService = new CategoryService(context, mc);

            websiteService = new WebsiteService(context, categoryService, new UserService(new PasswordService()));

            websiteAddModel.Name = "A dd Async";
            Guid id = await websiteService.AddAsync(websiteAddModel);

            Assert.AreNotEqual(id, Guid.Empty, "Add async should return a GUID.");
        }
Beispiel #3
0
        public void SetUp()
        {
            options = new DbContextOptionsBuilder <DataContext>()
                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                      .Options;

            using var context = new DataContext(options);
            var mc = new MemoryCache(new MemoryCacheOptions());
            var categoryService = new CategoryService(context, mc);

            context.Categories.Add(new Category {
                Code = CategoryCode.Sport, Name = "Sport"
            });
            context.SaveChanges();
            websiteService = new WebsiteService(context, categoryService, new UserService(new PasswordService()));

            websiteToDeleteId = Task.Run(() => websiteService.AddAsync(websiteAddModel)).GetAwaiter().GetResult();
        }
Beispiel #4
0
        public async Task <IActionResult> PostAsync([FromBody] WebsiteAddModel model)
        {
            Guid id = await websiteService.AddAsync(model);

            return(Created(nameof(PostAsync), new { id }));
        }