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); }
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)); } }
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); } }
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)); }