public void CreateApplication()
        {
            VolatileDataset store = new VolatileDataset();

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

            mockService.Setup(s => s.CreateApplication(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) => store.Applications.Last());

            IErrorsReportingService service     = mockService.Object;
            ErrorReportApplication  application = service.CreateApplication("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);
        }
Пример #2
0
        public void Db_ErrorsReportingService_CreateApplication_AlreadyExists()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();

                DalException ex = Assert.Throws <DalException>(() =>
                {
                    service.CreateApplication("TestApplicationAlreadyExisting", "a.a.a.a");
                });
                Assert.That(ex.errorType, Is.EqualTo(DalErrorType.SqlUniqueConstraintViolation));
            }
        }
Пример #3
0
        public void Db_ErrorsReportingService_CreateApplication()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();
                ErrorReportApplication  result  = service.CreateApplication("TestApplication", "1.0.0.0");

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

                this.dataSet.ApplicationsIds.Add(result.Id);
            }
        }
        public void CreateApplication_AlreadyExisting()
        {
            VolatileDataset store = new VolatileDataset();

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

            mockService.Setup(s => s.CreateApplication(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.Throws <DalException>(() =>
            {
                service.CreateApplication("TestApplicationAlreadyExisting", "1.0.0.0");
            });

            Assert.That(ex.errorType, Is.EqualTo(DalErrorType.SqlUniqueConstraintViolation));
        }