public void Cannot_Update_To_Duplicate_Server_Identities() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { ServerRegistrationRepository repository = CreateRepository(provider); IServerRegistration server = repository.Get(1); server.ServerIdentity = "COMPUTER2"; Assert.That(() => repository.Save(server), Throws.InstanceOf <DbException>()); } }
public void NoOuterScopeJustWorks() { var uowProvider = new PetaPocoUnitOfWorkProvider(Logger); var sqlSyntax = ApplicationContext.DatabaseContext.SqlSyntax; var lrepo = new LockingRepository <IServerRegistrationRepository>(uowProvider, x => CreateRepository(x, Logger, CacheHelper, sqlSyntax), new[] { Constants.Locks.Servers }, new[] { Constants.Locks.Servers }); IServerRegistration reg = null; lrepo.WithWriteLocked(xrepo => { xrepo.Repository.AddOrUpdate(reg = new ServerRegistration("a1234", "i1234", DateTime.Now)); // no need - autocommit by default //xrepo.UnitOfWork.Commit(); }); Assert.IsNull(((ScopeProvider)ApplicationContext.ScopeProvider).AmbientScope); Assert.AreNotEqual(0, reg.Id); // that's cheating somehow because it will not really hit the DB because of the cache var reg2 = lrepo.WithReadLocked(xrepo => { return(xrepo.Repository.Get(reg.Id)); }); Assert.IsNull(((ScopeProvider)ApplicationContext.ScopeProvider).AmbientScope); Assert.IsNotNull(reg2); Assert.AreEqual("a1234", reg2.ServerAddress); Assert.AreEqual("i1234", reg2.ServerIdentity); // this really makes sure there's something in database using (var scope = ApplicationContext.ScopeProvider.CreateScope()) { var reg3 = scope.Database.Fetch <dynamic>("SELECT * FROM umbracoServer WHERE id=@id", new { id = reg2.Id }).FirstOrDefault(); Assert.IsNotNull(reg3); Assert.AreEqual("a1234", reg3.address); Assert.AreEqual("i1234", reg3.computerName); } Assert.IsNull(((ScopeProvider)ApplicationContext.ScopeProvider).AmbientScope); }
public void Can_Perform_Get_On_Repository() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { ServerRegistrationRepository repository = CreateRepository(provider); // Act IServerRegistration server = repository.Get(1); // Assert Assert.That(server, Is.Not.Null); Assert.That(server.HasIdentity, Is.True); Assert.That(server.ServerAddress, Is.EqualTo("http://localhost")); } }
public static ServerRegistrationDto BuildDto(IServerRegistration entity) { var dto = new ServerRegistrationDto { ServerAddress = entity.ServerAddress, DateRegistered = entity.CreateDate, IsActive = entity.IsActive, IsSchedulingPublisher = ((ServerRegistration)entity).IsSchedulingPublisher, DateAccessed = entity.UpdateDate, ServerIdentity = entity.ServerIdentity, }; if (entity.HasIdentity) { dto.Id = entity.Id; } return(dto); }
public void Can_Perform_Delete_On_Repository() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { ServerRegistrationRepository repository = CreateRepository(provider); // Act IServerRegistration server = repository.Get(3); Assert.IsNotNull(server); repository.Delete(server); bool exists = repository.Exists(3); // Assert Assert.That(exists, Is.False); } }
public void Can_Perform_Update_On_Repository() { // Arrange IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { ServerRegistrationRepository repository = CreateRepository(provider); // Act IServerRegistration server = repository.Get(2); server.ServerAddress = "https://umbraco.com"; server.IsActive = true; repository.Save(server); IServerRegistration serverUpdated = repository.Get(2); // Assert Assert.That(serverUpdated, Is.Not.Null); Assert.That(serverUpdated.ServerAddress, Is.EqualTo("https://umbraco.com")); Assert.That(serverUpdated.IsActive, Is.EqualTo(true)); } }