public void MultipleActiveTenantTest() { var repository = new SpaceRepositoryFake(); var service = new SpaceManagementService(repository, new TrueSettingsStub(), new LoggerStub()); const int alice = 1001; const string aliceName = "Alice"; service.CreateSpace(alice); service.AssignTenant(alice, aliceName); service.IncrementPackages(alice); service.IncrementPackages(alice); Assert.Equal(2, service.GetPackages(alice)); Assert.Equal(2, service.GetPackages(alice)); service.AssignTenant(alice, aliceName); Assert.Equal(0, service.GetPackages(alice)); service.IncrementPackages(alice); service.IncrementPackages(alice); Assert.Equal(2, service.GetPackages(alice)); Assert.Equal(aliceName, repository.spaces[alice].Tenant); service.UnassignTenant(alice); Assert.Equal(string.Empty, repository.spaces[alice].Tenant); Assert.Equal(0, service.GetPackages(alice)); service.AssignTenant(alice, aliceName); Assert.Equal(aliceName, repository.spaces[alice].Tenant); Assert.Equal(0, service.GetPackages(alice)); service.IncrementPackages(alice); service.IncrementPackages(alice); Assert.Equal(2, service.GetPackages(alice)); service.ClearPackages(alice); Assert.Equal(0, service.GetPackages(alice)); service.IncrementPackages(alice); service.IncrementPackages(alice); Assert.Equal(2, service.GetPackages(alice)); const int bob = 1002; const string bobName = "Bob"; service.CreateSpace(bob); Assert.Equal(string.Empty, repository.spaces[bob].Tenant); service.AssignTenant(bob, bobName); Assert.Equal(bobName, repository.spaces[bob].Tenant); service.IncrementPackages(bob); service.ClearPackages(bob); service.IncrementPackages(bob); service.IncrementPackages(bob); service.IncrementPackages(bob); Assert.Equal(3, service.GetPackages(bob)); Assert.Equal(2, service.GetPackages(alice)); }
public void CreateSpace_WhenSpaceCreationIsNotAllowed_ThrowsInvalidOperationException() { var settings = new SettingsStub() { SpaceCreationAllowedValue = false }; var service = new SpaceManagementService(new SpaceRepositoryDummy(), settings); Assert.Throws <InvalidOperationException>(() => service.CreateSpace(1)); }
public void CreateSpace_WhenSpaceAlreadyExists_ThrowsDuplicateSpaceException_2() { var repository = new SpaceRepositoryMock(); var service = new SpaceManagementService(repository, new TrueSettingsStub(), new LoggerStub()); const int location = 999; repository.SetupRead(location); Assert.Throws <DuplicateSpaceException>(() => service.CreateSpace(location)); Assert.Empty(repository.ReadQueue); }
public void CreateSpace_LogsMessageBeforeCreation() { var logger = new LoggerSpy(); var service = new SpaceManagementService(new SpaceRepositoryDummy(), new TrueSettingsStub(), logger); const int location = 999; service.CreateSpace(location); var logMessage = logger.LogCalls.Single(); Assert.Equal($"Creating space {location}...", logMessage); }
public void CreateSpace_CreatesSpaceCorrectly() { var repository = new SpaceRepositoryFake(); var service = new SpaceManagementService(repository, new TrueSettingsStub(), new LoggerStub()); const int location = 999; service.CreateSpace(location); var space = repository.Read(location); Assert.NotNull(space); Assert.Equal(location, space.Location); Assert.Equal(string.Empty, space.Tenant); Assert.Equal(0, space.Packages); }
public void CreateSpace_WhenSpaceAlreadyExists_ThrowsDuplicateSpaceException() { var repository = new SpaceRepositoryMock(); var service = new SpaceManagementService(repository, new TrueSettingsStub(), new LoggerStub()); const int location = 999; var readFuncWasCalled = false; repository.ReadFunc = loc => { readFuncWasCalled = true; Assert.Equal(location, loc); return(new Space() { Location = loc }); }; Assert.Throws <DuplicateSpaceException>(() => service.CreateSpace(location)); Assert.True(readFuncWasCalled); }
public void CreateSpace_RequiresValidLocation() { var service = new SpaceManagementService(new SpaceRepositoryDummy(), new SettingsDummy()); Assert.Throws <ArgumentOutOfRangeException>(() => service.CreateSpace(0)); }