public void SettingsRead_Execute_SecurityReadDoesThrowException_HasErrorsIsTrueAndDefaultPermissionsAreAssigned() { //------------Setup for test-------------------------- const string invalidFormat = "Invalid format."; var securityRead = new Func <IEsbManagementEndpoint>(() => { throw new JsonException(invalidFormat); }); var settingsRead = new TestSettingsRead(securityRead); //------------Execute Test--------------------------- var jsonPermissions = settingsRead.Execute(null, null); var settings = JsonConvert.DeserializeObject <Settings>(jsonPermissions.ToString()); //------------Assert Results------------------------- Assert.IsNotNull(settings); Assert.IsNotNull(settings.Security); Assert.IsTrue(settings.HasError); StringAssert.Contains(settings.Error, invalidFormat); var expected = SecurityRead.DefaultPermissions[0]; var actual = settings.Security.WindowsGroupPermissions[0]; var result = new WindowsGroupPermissionEqualityComparer().Equals(expected, actual); Assert.IsTrue(result); }
public void SettingsRead_Execute_SecurityReadDoesNotThrowException_HasErrorsIsFalseAndSecurityPermissionsAreAssigned() { //------------Setup for test-------------------------- var serializer = new Dev2JsonSerializer(); var securityPermissions = new List <WindowsGroupPermission> { new WindowsGroupPermission { IsServer = true, WindowsGroup = "TestGroup", Permissions = AuthorizationContext.DeployFrom.ToPermissions() }, new WindowsGroupPermission { IsServer = true, WindowsGroup = "NETWORK SERVICE", Permissions = AuthorizationContext.DeployTo.ToPermissions() } }; var securitySettingsTO = new SecuritySettingsTO(securityPermissions); var securityRead = new Func <IEsbManagementEndpoint>(() => { var endpoint = new Mock <IEsbManagementEndpoint>(); endpoint.Setup(e => e.Execute(It.IsAny <Dictionary <string, StringBuilder> >(), It.IsAny <IWorkspace>())) .Returns(new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTO)); return(endpoint.Object); }); var mockPerfCounterRepo = new Mock <IPerformanceCounterRepository>(); mockPerfCounterRepo.Setup(repository => repository.Counters).Returns(new PerformanceCounterTo()); CustomContainer.Register(mockPerfCounterRepo.Object); var settingsRead = new TestSettingsRead(securityRead); //------------Execute Test--------------------------- var jsonPermissions = settingsRead.Execute(null, null); var settings = serializer.Deserialize <Settings>(jsonPermissions.ToString()); //------------Assert Results------------------------- Assert.IsNotNull(settings); Assert.IsNotNull(settings.Security); Assert.IsFalse(settings.HasError); var comparer = new WindowsGroupPermissionEqualityComparer(); Assert.AreEqual(2, settings.Security.WindowsGroupPermissions.Count); for (var i = 0; i < securityPermissions.Count; i++) { var result = comparer.Equals(securityPermissions[i], settings.Security.WindowsGroupPermissions[i]); Assert.IsTrue(result); } }
public void SettingsRead_Execute_SecurityReadDoesNotThrowException_HasErrorsIsFalseAndSecurityPermissionsAreAssigned() { //------------Setup for test-------------------------- var securityPermissions = new List<WindowsGroupPermission> { new WindowsGroupPermission { IsServer = true, WindowsGroup = "TestGroup", Permissions = AuthorizationContext.DeployFrom.ToPermissions() }, new WindowsGroupPermission { IsServer = true, WindowsGroup = "NETWORK SERVICE", Permissions = AuthorizationContext.DeployTo.ToPermissions() } }; var securitySettingsTO = new SecuritySettingsTO(securityPermissions); var securityRead = new Func<IEsbManagementEndpoint>(() => { var endpoint = new Mock<IEsbManagementEndpoint>(); endpoint.Setup(e => e.Execute(It.IsAny<Dictionary<string, StringBuilder>>(), It.IsAny<IWorkspace>())) .Returns(new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTO)); return endpoint.Object; }); var settingsRead = new TestSettingsRead(securityRead); //------------Execute Test--------------------------- var jsonPermissions = settingsRead.Execute(null, null); var settings = JsonConvert.DeserializeObject<Settings>(jsonPermissions.ToString()); //------------Assert Results------------------------- Assert.IsNotNull(settings); Assert.IsNotNull(settings.Security); Assert.IsFalse(settings.HasError); var comparer = new WindowsGroupPermissionEqualityComparer(); Assert.AreEqual(2, settings.Security.WindowsGroupPermissions.Count); for(var i = 0; i < securityPermissions.Count; i++) { var result = comparer.Equals(securityPermissions[i], settings.Security.WindowsGroupPermissions[i]); Assert.IsTrue(result); } }
public void SettingsRead_Execute_SecurityReadDoesThrowException_HasErrorsIsTrueAndDefaultPermissionsAreAssigned() { //------------Setup for test-------------------------- const string invalidFormat = "Invalid format."; var securityRead = new Func<IEsbManagementEndpoint>(() => { throw new JsonException(invalidFormat); }); var settingsRead = new TestSettingsRead(securityRead); //------------Execute Test--------------------------- var jsonPermissions = settingsRead.Execute(null, null); var settings = JsonConvert.DeserializeObject<Settings>(jsonPermissions.ToString()); //------------Assert Results------------------------- Assert.IsNotNull(settings); Assert.IsNotNull(settings.Security); Assert.IsTrue(settings.HasError); StringAssert.Contains(settings.Error, invalidFormat); var expected = SecurityRead.DefaultPermissions[0]; var actual = settings.Security.WindowsGroupPermissions[0]; var result = new WindowsGroupPermissionEqualityComparer().Equals(expected, actual); Assert.IsTrue(result); }