Beispiel #1
0
        public async Task CreateProject_CallWithMockedIProject_ThrowsAndCatchesProjectException()
        {
            // Arrange
            var mock        = new Mock <IProject>();
            var projectGuid = Guid.Empty;
            var projectDto  = new ProjectDto()
            {
                Id   = projectGuid,
                Name = "Project"
            };

            var message = "ExceptionThrown";
            var ex      = new ProjectException(message);

            mock.Setup(project => project.CreateProjectAsync(projectDto)).ThrowsAsync(ex);
            var projectsController = new ProjectsController(mock.Object);

            // Act
            var result = await projectsController.CreateProject(projectDto);

            var response     = (BadRequestObjectResult)result;
            var objectResult = (ResponseDto <ErrorDto>)response.Value;

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
            Assert.IsType <ResponseDto <ErrorDto> >(response.Value);
            Assert.Equal(message, objectResult.Data.Message);
        }
        public void AssertionsPassIfNoErrors()
        {
            var noErrors = new ProjectException[0];

            noErrors.Assert();
            noErrors.Assert(s => new Exception(s));
            noErrors.AssertThrowsFirst();
        }
        public int PostException(ProjectExceptionEntities generatedException)
        {
            IProjectExceptionOperations exceptionOperations = new ProjectExceptionOperations();

            ProjectException exceptionToInsert = MapEntities.Map <ProjectExceptionEntities, ProjectException>(generatedException);

            exceptionOperations.LogException(exceptionToInsert);
            return(exceptionToInsert.Id);
        }
        public static void LogExceptionFromApplication(ProjectExceptionEntities exception)
        {
            IProjectExceptionOperations projectExceptionOperation = new ProjectExceptionOperations();
            ProjectException            generatedException        = new ProjectException();

            generatedException.CreatedDate = DateTime.Now;
            generatedException.Message     = exception.Message;
            generatedException.ProjectType = Convert.ToString(ProjectTypeEnum.ServiceLayer);
            generatedException.StackTrace  = exception.StackTrace;
            projectExceptionOperation.LogException(generatedException);
        }
        public void AssertionsFailIfErrors()
        {
            var first  = new UnknownComponentException("First");
            var second = new UnknownLayerException("Second");
            var errors = new ProjectException[] { first, second };

            Assert.Throws <Exception>(() => errors.Assert());
            Assert.Throws <AssertionException>(() => errors.Assert(s => new AssertionException(s)));
            var e = Assert.Throws <UnknownComponentException>(() => errors.AssertThrowsFirst());

            Assert.AreEqual(first, e);
        }
Beispiel #6
0
 public int LogException(ProjectException exception)
 {
     db.ProjectExceptions.Add(exception);
     db.SaveChanges();
     return(exception.Id);
 }