Exemple #1
0
        public void If_no_exception_no_response_is_set()
        {
            // 1. Arrange
            var attr    = new ProcessErrorAttribute();
            var context = new HttpActionExecutedContext {
                Exception = null
            };

            // 2.Act
            attr.OnActionExecuted(context);
            // 3. Assert
            context.Response.Should().BeNull();
        }
Exemple #2
0
        public void On_exception_response_is_set()
        {
            // 1. Arrange
            var attr         = new ProcessErrorAttribute();
            var errorMessage = Guid.NewGuid().ToString();
            var exception    = new Exception(errorMessage);
            var context      = new HttpActionExecutedContext
            {
                Exception     = exception,
                ActionContext = new HttpActionContext()
            };

            // ReSharper disable once RedundantAssignment
            string description = errorMessage;
            var    mErr        = new Mock <IErrorManager>(MockBehavior.Strict);

            mErr
            .Setup(em => em.GetErrorCodeByException(exception, out description))
            .Returns(GameApiErrorCode.SystemError);
            attr.ErrorManager = mErr.Object;

            var mLog = new Mock <IGameProviderLog>(MockBehavior.Strict);

            mLog
            .Setup(l => l.LogError(It.IsAny <string>(), exception));
            attr.Log = mLog.Object;

            var mJson = new Mock <IJsonSerializationProvider>(MockBehavior.Strict);

            mJson
            .Setup(j => j.SerializeToString(It.IsAny <BetCommandResponse>()))
            .Returns <BetCommandResponse>(o => o.ErrorDescription);
            attr.Json = mJson.Object;

            // 2. Act
            attr.OnActionExecuted(context);

            // 3. Assert
            Assert.That(context.Response.Content.ReadAsStringAsync().Result, Is.StringContaining(errorMessage));
            mLog.Verify(l => l.LogError(It.IsAny <string>(), exception), Times.Once());
        }