public void CleansUpWhenItFails() { var spec = new ContainerSpec { Handle = "handle", }; ContainerHostService.StartContainerHost(null, null, null, null) .ThrowsForAnyArgs(new Exception()); try { Service.CreateContainer(spec); } catch (Exception) { // Expect this exception. } // Created and deleted the user UserManager.Received(1).CreateUser(Arg.Any <string>()); UserManager.Received(1).DeleteUser(Arg.Any <string>()); UserManager.Received(1).CreateProfile(Arg.Any <string>()); UserManager.Received(1).DeleteProfile(Arg.Any <string>()); containerDirectory.Received().Destroy(); }
public ContainerServiceTests() { ContainerBasePath = @"C:\Containers"; ContainerUserGroup = "ContainerUsers"; ContainerPropertiesService = Substitute.For <IContainerPropertyService>(); FileSystem = Substitute.For <IFileSystemManager>(); Id = "DEADBEEF"; HandleHelper = Substitute.For <ContainerHandleHelper>(); HandleHelper.GenerateId(null).ReturnsForAnyArgs(Id); ProcessRunner = Substitute.For <IProcessRunner>(); TcpPortManager = Substitute.For <ILocalTcpPortManager>(); UserManager = Substitute.For <IUserManager>(); ContainerHostClient = Substitute.For <IContainerHostClient>(); ContainerHostService = Substitute.For <IContainerHostService>(); ContainerHostService.StartContainerHost(null, null, null, null) .ReturnsForAnyArgs(ContainerHostClient); UserManager.CreateUser(null).ReturnsForAnyArgs(new NetworkCredential("username", "password")); sid = "S-1234"; UserManager.GetSID(null).ReturnsForAnyArgs(sid); diskQuotaManager = Substitute.For <IDiskQuotaManager>(); containerDiskQuota = Substitute.For <IContainerDiskQuota>(); diskQuotaManager.CreateDiskQuotaControl(null, "").ReturnsForAnyArgs(containerDiskQuota); var directoryFactory = Substitute.For <IContainerDirectoryFactory>(); containerDirectory = Substitute.For <IContainerDirectory>(); directoryFactory.Create(FileSystem, ContainerBasePath, Id).Returns(containerDirectory); var containerFactory = new TestContainerFactory(); Service = new ContainerService( HandleHelper, UserManager, FileSystem, ContainerPropertiesService, TcpPortManager, ProcessRunner, ContainerHostService, diskQuotaManager, directoryFactory, containerFactory, ContainerBasePath ); }