public async Task UpdateScope(Boolean mediatorResultShouldBeSuccessful) { Random random = new Random(); Guid id = random.NextGuid(); String name = random.GetAlphanumericString(); String description = random.GetAlphanumericString(); Guid? parentId = random.NextBoolean() == true?random.NextGuid() : new Guid?(); var addressProperties = new DHCPv4ScopeAddressPropertyReqest(); var resolverInfo = new CreateScopeResolverRequest { Typename = random.GetAlphanumericString(), PropertiesAndValues = new Dictionary <String, String>() }; Mock <ILoggerFactory> factoryMock = new Mock <ILoggerFactory>(MockBehavior.Strict); factoryMock.Setup(x => x.CreateLogger(It.IsAny <String>())).Returns(Mock.Of <ILogger <DHCPv4RootScope> >()); DHCPv4RootScope rootScope = new DHCPv4RootScope(random.NextGuid(), Mock.Of <IScopeResolverManager <DHCPv4Packet, IPv4Address> >(MockBehavior.Strict), factoryMock.Object); Mock <IMediator> mediatorMock = new Mock <IMediator>(MockBehavior.Strict); mediatorMock.Setup(x => x.Send(It.Is <UpdateDHCPv4ScopeCommand>(y => y.ScopeId == id && y.Name == name && y.Description == description && y.ParentId == parentId && y.AddressProperties == addressProperties && y.Resolver == resolverInfo ), It.IsAny <CancellationToken>())).ReturnsAsync(mediatorResultShouldBeSuccessful).Verifiable(); var request = new CreateOrUpdateDHCPv4ScopeRequest { Name = name, Description = description, AddressProperties = addressProperties, ParentId = parentId, Resolver = resolverInfo, }; var controller = new DHCPv4ScopeController(mediatorMock.Object, Mock.Of <IScopeResolverManager <DHCPv4Packet, IPv4Address> >(MockBehavior.Strict), rootScope); var actionResult = await controller.UpdateScope(request, id); if (mediatorResultShouldBeSuccessful == true) { actionResult.EnsureNoContentResult(); } else { actionResult.EnsureBadRequestObjectResult("unable to execute service operation"); } mediatorMock.Verify(); }
public CreateOrUpdateDHCPv4ScopeRequest GetRequest() { var request = new CreateOrUpdateDHCPv4ScopeRequest { Name = GenerellProperties.Name, Description = GenerellProperties.Description, ParentId = GenerellProperties.HasParent == false ? new Guid?() : GenerellProperties.ParentId, AddressProperties = AddressRelatedProperties.GetRequest(), Properties = ScopeProperties.GetRequest(), Resolver = ResolverProperties.GetRequest(), }; return(request); }
public async Task <Boolean> CreateDHCPv4Scope(CreateOrUpdateDHCPv4ScopeRequest request) => await ExecuteCommand(() => _client.PostAsync("api/scopes/dhcpv4/", GetStringContentAsJson(request)));
public async Task <Boolean> UpdateDHCPv4Scope(CreateOrUpdateDHCPv4ScopeRequest request, String scopeId) => await ExecuteCommand(() => _client.PutAsync($"api/scopes/dhcpv4/{scopeId}", GetStringContentAsJson(request)));