Esempio n. 1
0
        public async Task CreateApplicationAsync()
        {
            VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.CreateApplicationAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((name, version) =>
            {
                store.Applications.Add(new ErrorReportApplication
                {
                    Id           = store.Applications.Count + 1,
                    Name         = name,
                    Version      = version,
                    FirstRunDate = DateTime.Now,
                    RowVersion   = new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 },
                    Exceptions   = new List <ErrorReportException>()
                });
            })
            .Returns <string, string>((name, version) => Task.FromResult <ErrorReportApplication>(store.Applications.Last()));

            IErrorsReportingService service     = mockService.Object;
            ErrorReportApplication  application = await service.CreateApplicationAsync("TestApplication", "1.0.0.0");

            Assert.AreEqual(5, store.Applications.Count);
            Assert.AreEqual(store.Applications.Last().Id, application.Id);
            Assert.AreEqual(store.Applications.Last().FirstRunDate, application.FirstRunDate);
            Assert.AreEqual(store.Applications.Last().Name, application.Name);
        }
Esempio n. 2
0
        public void Db_ErrorsReportingService_LogExceptionAsync_WithInner()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();

                try
                {
                    ExceptionGenerator.ThrowsTwo();
                }
                catch (Exception exception)
                {
                    int?id = null;
                    Assert.That(async() =>
                    {
                        id = await service.LogExceptionAsync(this.dataSet.ApplicationsIds.ElementAt(0), exception, "ErrorType.Specific");
                    }, Throws.Nothing);

                    Assert.IsNotNull(id);

                    ErrorReportException ex      = this.exceptionsSqlHelper.GetBy(id.Value);
                    ErrorReportException innerEx = this.exceptionsSqlHelper.GetBy(ex.IdInnerException.Value);

                    Assert.AreEqual("Two", ex.Message);
                    Assert.AreEqual("One", innerEx.Message);
                }
            }
        }
Esempio n. 3
0
        public async Task Db_ErrorsReportingService_GetApplicationAsync()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service     = childContainer.Resolve <IErrorsReportingService>();
                ErrorReportApplication  application = await service.GetApplicationAsync("TestApplicationAlreadyExisting", "a.a.a.a");

                Assert.Greater(application.Id, 0);
                Assert.AreEqual(new DateTime(2000, 1, 1), application.FirstRunDate);
            }
        }
Esempio n. 4
0
        public void Db_ErrorsReportingService_CreateApplicationAsync_AlreadyExists()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();

                DalException ex = Assert.ThrowsAsync <DalException>(async() =>
                {
                    await service.CreateApplicationAsync("TestApplicationAlreadyExisting", "a.a.a.a");
                });
                Assert.That(ex.errorType, Is.EqualTo(DalErrorType.SqlUniqueConstraintViolation));
            }
        }
Esempio n. 5
0
        public async Task Db_ErrorsReportingService_CreateApplicationAsync()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();
                ErrorReportApplication  result  = await service.CreateApplicationAsync("TestApplication", "a.a.a.a");

                Assert.IsNotNull(result);
                Assert.Greater(result.Id, 0);

                this.dataSet.ApplicationsIds.Add(result.Id);
            }
        }
Esempio n. 6
0
        public void Db_ErrorsReportingService_GetApplicationAsync_NotExisting()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service     = childContainer.Resolve <IErrorsReportingService>();
                ErrorReportApplication  application = null;
                Assert.That(async() =>
                {
                    application = await service.GetApplicationAsync("TestApplicationAlreadyExisting", "z.z.z.z");
                }, Throws.Nothing);

                Assert.IsNull(application);
            }
        }
        public void GetApplication()
        {
            VolatileDataset store = new VolatileDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.GetApplication(It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string>((name, version) => store.Applications.Single(a => a.Name == name && a.Version == version));

            IErrorsReportingService service     = mockService.Object;
            ErrorReportApplication  application = service.GetApplication("TestApplicationAlreadyExisting", "1.0.0.0");

            Assert.AreEqual(1, application.Id);
            Assert.AreEqual(new DateTime(2000, 1, 1), application.FirstRunDate);
        }
Esempio n. 8
0
        public void LogExceptionAsync()
        {
            VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.LogExceptionAsync(It.IsIn <int>(store.Applications.Select(a => a.Id)),
                                                       It.IsAny <Exception>(),
                                                       It.IsAny <string>()))
            .Callback <int, Exception, string>((idApplicaton, exception, errorCore) =>
            {
                store.Exceptions.Add(new ErrorReportException
                {
                    Id              = 1,
                    IdApplication   = idApplicaton,
                    Type            = exception.GetType().ToString(),
                    Message         = exception.Message,
                    Source          = exception.Source,
                    SiteModule      = (exception.TargetSite != null && exception.TargetSite.Module != null) ? exception.TargetSite.Module.Name : null,
                    SiteName        = exception.TargetSite.Name,
                    StackTrace      = exception.StackTrace,
                    HelpLink        = exception.HelpLink,
                    Date            = DateTime.Now,
                    CustomErrorType = errorCore,
                });
            })
            .Returns(Task.FromResult <int?>(1));

            IErrorsReportingService service = mockService.Object;

            try
            {
                ExceptionGenerator.ThrowsOne();
            }
            catch (Exception exception)
            {
                int?id = null;
                Assert.That(async() =>
                {
                    id = await service.LogExceptionAsync(store.Applications.First().Id, exception, "ErrorType.Specific");
                }, Throws.Nothing);

                Assert.IsNotNull(id);

                Assert.AreEqual("One", store.Exceptions.First().Message);
            }
        }
Esempio n. 9
0
        public void CreateApplicationAsync_AlreadyExisting()
        {
            VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.CreateApplicationAsync(It.IsIn <string>(store.Applications.Select(a => a.Name)), It.IsAny <string>()))
            .Throws(new DalException(DalErrorType.SqlUniqueConstraintViolation, "Application already exists"));

            IErrorsReportingService service = mockService.Object;

            DalException ex = Assert.ThrowsAsync <DalException>(async() =>
            {
                await service.CreateApplicationAsync("TestApplicationAlreadyExisting", "1.0.0.0");
            });

            Assert.That(ex.errorType, Is.EqualTo(DalErrorType.SqlUniqueConstraintViolation));
        }
        public void GetApplication_NotExisting()
        {
            VolatileDataset store = new VolatileDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.GetApplication(It.IsNotIn <string>(store.Applications.Select(a => a.Name)), It.IsAny <string>()))
            .Returns <string, string>(null);

            IErrorsReportingService service = mockService.Object;

            ErrorReportApplication application = null;

            Assert.That(() =>
            {
                application = service.GetApplication("TestApplicationNotExisting", "1.0.0.0");
            }, Throws.Nothing);

            Assert.IsNull(application);
        }
Esempio n. 11
0
        public void GetApplicationAsync_NotExisting()
        {
            VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.GetApplicationAsync(It.IsNotIn <string>(store.Applications.Select(a => a.Name)), It.IsAny <string>()))
            .Returns <string, string>((name, version) =>
                                      Task.FromResult <ErrorReportApplication>(null));

            IErrorsReportingService service = mockService.Object;

            ErrorReportApplication application = null;

            Assert.That(async() =>
            {
                application = await service.GetApplicationAsync("TestApplicationNotExisting", "1.0.0.0");
            }, Throws.Nothing);

            Assert.IsNull(application);
        }
 public ErrorsReportingManager(IErrorsReportingService reportingService) => this.reportingService = reportingService;