コード例 #1
0
        private void SaveLog(WebContexts webContexts)
        {
            if (webContexts == null)
            {
                throw new ArgumentNullException("webContexts");
            }

            if (!_userActivityLoggingState.IsUserActivityActivated)
            {
                return;
            }

            if (_desctiption == null)
            {
                _desctiption = _descriptionGetter.GetDefaultDescription(webContexts);
            }

            var identity = (FormsIdentity)webContexts.CurrentHttpContext.User.Identity;
            var userId = _coockieParser.GetUserId(identity);
            var userRoleName = _coockieParser.GetUserRoleName(identity);
            var userLogin = _coockieParser.GetUserLogin(identity);

            _logService.SaveActivityAsync(new UserActivity
            {
                Date = DateTime.Now,
                Description = _desctiption,
                EntityState = EntityState.Added,
                UserId = userId,
                UserName = userLogin,
                UserRoleName = userRoleName
            });
        }
コード例 #2
0
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            var contexts = new WebContexts(HttpContext.Current, filterContext);

            SaveLog(contexts);
        }
コード例 #3
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext == null)
            {
                throw new ArgumentNullException("actionExecutedContext");
            }

            var contexts = new WebContexts(HttpContext.Current, actionExecutedContext);

            SaveLog(contexts);
        }
コード例 #4
0
        public void GetDefaultDesctiption_ForMvc_Test()
        {
            //Arange
            var resultExecutedContext = new ResultExecutedContext
            {
                Controller = new PrompterController()
            };

            resultExecutedContext.Controller
                .ControllerContext = new ActionExecutedContext
            {
                Controller = new PrompterController()
            };

            HttpContext.Current = new HttpContext(
                new HttpRequest(null,
                    "http://testUrl/test",
                    null),
                new HttpResponse(null));

            var webContexts = new WebContexts(HttpContext.Current, resultExecutedContext);

            var defaultUserActivityDesctiption = new DefaultUserActivityDescription();

            //Act
            var actual = defaultUserActivityDesctiption
                .GetDefaultDescription(webContexts);
            
            //Assert
            Assert.That(actual != null);
            Assert.That(actual.Contains("/test"));
            Assert.That(actual.Contains("PrompterController"));
            Assert.That(actual.Contains("Mvc"));
            Assert.That(actual.Contains("GET"));

            Assert.Throws<ArgumentNullException>(() =>
            {
                defaultUserActivityDesctiption
                    .GetDefaultDescription(null);
            });
        }
コード例 #5
0
        public string GetDefaultDescription(WebContexts webContext)
        {
            if (webContext == null)
            {
                throw new ArgumentNullException("webContext");
            }

            _webContexts = webContext;

            if (_webContexts.ResultExecutedContext != null)
            {
                _controllerName = GetMvcControllerName(_webContexts.ResultExecutedContext);
                _controllerType = "Mvc";
            }

            if (_webContexts.HttpActionExecutedContext != null)
            {
                _controllerName = GetWebApiControllerName(_webContexts.HttpActionExecutedContext);
                _controllerType = "WebApi";
            }

            return FormDefaultDescription();
        }
コード例 #6
0
        public void GetDefaultDesctiption_ForWebApi_Test()
        {
            //Arange
            var dummyUserService = new Mock<IUserService>();
            var dummyUserMapper = new Mock<IUserMapper>();
            

            var actionExecutedContext = new HttpActionExecutedContext
            {
                ActionContext = new HttpActionContext()
            };

            actionExecutedContext.ActionContext
                .ControllerContext = new HttpControllerContext
                {
                    Controller = new WebApplication.WebApi.PrompterController(
                        dummyUserService.Object,
                        dummyUserMapper.Object)
                };

            HttpContext.Current = new HttpContext(
                new HttpRequest(null,
                    "http://testUrl/test",
                    null),
                new HttpResponse(null));

            var webContexts = new WebContexts(HttpContext.Current, actionExecutedContext);

            var defaultUserActivityDesctiption = new DefaultUserActivityDescription();

            //Act
            var actual = defaultUserActivityDesctiption
                .GetDefaultDescription(webContexts);

            //Assert
            Assert.That(actual != null);
            Assert.That(actual.Contains("/test"));
            Assert.That(actual.Contains("PrompterController"));
            Assert.That(actual.Contains("WebApi"));
            Assert.That(actual.Contains("GET"));

            Assert.Throws<ArgumentNullException>(() =>
            {
                defaultUserActivityDesctiption
                    .GetDefaultDescription(null);
            });
        }