Пример #1
0
        public async Task <IActionResult> Create([Bind("Word,Case")] Anagram anagram)
        {
            try
            {
                if (string.IsNullOrEmpty(anagram.Word) || string.IsNullOrEmpty(anagram.Category))
                {
                    throw new Exception("You must fill all the fields");
                }

                _cookiesHandler.ClearAllCookies();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                await _wordService.InsertWord(anagram);

                sw.Stop();

                await _userLogService.AddLog(sw.Elapsed, UserActionTypes.InsertWord);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                @ViewData["Error"] = ex.Message;
                return(View(anagram));
            }
        }
Пример #2
0
        public void ClearAllCookiesSuccess()
        {
            var cookiesList = new List <string>()
            {
                "cookie1"
            };

            _httpContextMock.HttpContext.Request.Cookies.Keys.Returns(cookiesList);
            _httpContextMock.HttpContext.Response.Cookies.Delete(Arg.Any <string>());

            _cookiesHandlerService.ClearAllCookies();

            _httpContextMock.Received().HttpContext.Response.Cookies.Delete(Arg.Any <string>());
        }
        public async Task CreateSuccessWhenAllMandatoryFieldsFilled()
        {
            _cookiesHandlerServiceMock.ClearAllCookies();
            await _wordServiceMock.InsertWord(Arg.Any <Anagram>());

            await _userLogServiceMock.AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>());

            await _contextMock.SaveChangesAsync();

            var result = await _controller.Create(_anagram) as RedirectToActionResult;

            _cookiesHandlerServiceMock.Received().ClearAllCookies();
            await _wordServiceMock.Received().InsertWord(Arg.Any <Anagram>());

            await _userLogServiceMock.Received().AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>());

            await _contextMock.Received().SaveChangesAsync();

            Assert.AreEqual("Index", result.ActionName);
        }