示例#1
0
        protected virtual void EditNoErrorsTest(ICudController <ViewModelType> sut)
        {
            var viewModel = (ViewModelType)Activator.CreateInstance(typeof(ViewModelType));

            var result = sut.Edit(viewModel);

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            _MapperMock.Verify(m => m.Map <ModelType>(It.IsAny <ViewModelType>()), Times.Once);
            _MapperMock.Verify(m => m.Map <ViewModelType>(It.IsAny <ModelType>()), Times.Once);
        }
示例#2
0
        protected virtual void DeleteBusinessErrorTest(ICudController <ViewModelType> sut, Action setupBl)
        {
            setupBl();

            var result = sut.Delete(Guid.NewGuid());

            ;
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual((int)BLErrorCodes.Duplicate, (int)(result as BadRequestObjectResult).Value);
        }
示例#3
0
        protected virtual void EditInvalidModelStateTest(ICudController <ViewModelType> sut)
        {
            var viewModel = (ViewModelType)Activator.CreateInstance(typeof(ViewModelType));

            sut.ModelState.AddModelError("test", "test");

            var result = sut.Edit(viewModel);

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
            _MapperMock.Verify(m => m.Map <ModelType>(It.IsAny <ViewModelType>()), Times.Never);
            _MapperMock.Verify(m => m.Map <ViewModelType>(It.IsAny <ModelType>()), Times.Never);
        }
示例#4
0
        protected virtual void AddBusinessErrorTest(ICudController <ViewModelType> sut, Action setupBl)
        {
            var viewModel = (ViewModelType)Activator.CreateInstance(typeof(ViewModelType));

            setupBl();

            var result = sut.Add(viewModel);

            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual((int)BLErrorCodes.Duplicate, (int)(result as BadRequestObjectResult).Value);
            _MapperMock.Verify(m => m.Map <ModelType>(It.IsAny <ViewModelType>()), Times.Once);
            _MapperMock.Verify(m => m.Map <ViewModelType>(It.IsAny <ModelType>()), Times.Never);
        }
示例#5
0
        protected void SetControllerContext(ICudController <ViewModelType> sut)
        {
            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Username", "Token"), new[]
            {
                new Claim(RaceVenturaAPI.Helpers.Constants.Strings.JwtClaimIdentifiers.Id, Guid.NewGuid().ToString()),
                new Claim(RaceVenturaAPI.Helpers.Constants.Strings.JwtClaimIdentifiers.Rol, RaceVenturaAPI.Helpers.Constants.Strings.JwtClaims.ApiAccess)
            })));

            sut.ControllerContext.HttpContext = contextMock.Object;

            Assert.IsNotNull(sut.HttpContext.User);
        }
示例#6
0
        protected virtual void DeleteExceptionTest(ICudController <ViewModelType> sut, Action <Exception> setupBl)
        {
            var viewModel        = (ViewModelType)Activator.CreateInstance(typeof(ViewModelType));
            var exceptionMessage = "a";
            var exception        = new Exception(exceptionMessage);

            setupBl(exception);

            var result = sut.Delete(Guid.NewGuid());

            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(500, (result as StatusCodeResult).StatusCode);

            _LoggerMock.VerifyLog(LogLevel.Error, Times.Once, $"Error in {typeof(ControllerType)}: {exceptionMessage}");
        }
示例#7
0
        protected virtual void DeleteNoErrorsTest(ICudController <ViewModelType> sut)
        {
            var result = sut.Delete(Guid.NewGuid());

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
        }