public async Task Should_be_successfully_deleted() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var response = new List<MessageRedirectFromJson>(); var messageRedirectId = DeterministicGuid.MakeId(redirect.fromphysicaladdress); await Define<Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect); await this.Delete($"/api/redirects/{messageRedirectId}/"); var result = await this.TryGetMany<MessageRedirectFromJson>("/api/redirects"); response = result; return true; }) .Run(); Assert.AreEqual(0, response.Count, "Expected no redirects after delete"); }
public async Task Should_return_conflict_when_it_will_create_a_dependency() { var updateRedirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var conflictRedirect = new RedirectRequest { fromphysicaladdress = "endpointC@machine3", tophysicaladdress = "endpointD@machine4" }; var messageRedirectId = DeterministicGuid.MakeId(updateRedirect.fromphysicaladdress); await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", updateRedirect); await this.Post("/api/redirects", conflictRedirect); await this.Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = conflictRedirect.fromphysicaladdress }, status => status != HttpStatusCode.Conflict); return(true); }).Run(); }
public async Task Should_be_added_and_accessible_via_the_api() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var response = new List <MessageRedirectFromJson>(); await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect); var result = await this.TryGetMany <MessageRedirectFromJson>("/api/redirects"); response = result; return(result); }).Run(); Assert.AreEqual(1, response.Count, "Expected 1 redirect to be created"); Assert.AreEqual(DeterministicGuid.MakeId(redirect.fromphysicaladdress), response[0].message_redirect_id, "Message Redirect Id mismatch"); Assert.AreEqual(redirect.fromphysicaladdress, response[0].from_physical_address, "From physical address mismatch"); Assert.AreEqual(redirect.tophysicaladdress, response[0].to_physical_address, "To physical address mismatch"); Assert.Greater(response[0].last_modified, DateTime.MinValue, "Last modified was not set"); }
public async Task Should_fail_validation_with_dependent_redirects() { var toAddress = "endpointTo@machineTo"; var dependentCount = 3; await Define <Context>() .Done(async ctx => { for (var i = 0; i < dependentCount; i++) { var redirect = new RedirectRequest { fromphysicaladdress = $"endpoint{i}@machine{i}", tophysicaladdress = toAddress }; await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); } await this.Post("/api/redirects", new RedirectRequest { fromphysicaladdress = toAddress, tophysicaladdress = "endpointX@machineX" }, status => status != HttpStatusCode.Conflict); return(true); }).Run(); }
public async Task Should_fail_validation_with_blank_tophysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = string.Empty }; await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.BadRequest); return(true); }).Run(); }
public async Task Should_fail_validation_with_different_tophysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); redirect.tophysicaladdress = "endpointC@machine3"; await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.Conflict); return(true); }).Run(); }
public async Task Should_be_successfully_updated() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var messageRedirectId = DeterministicGuid.MakeId(redirect.fromphysicaladdress); const string newTo = "endpointC@machine3"; var context = await Define <Context>().Done(async c => { await this.Post("/api/redirects", redirect); var result = await this.TryGetMany <MessageRedirectFromJson>("/api/redirects"); c.CreatedAt = result.Items[0].last_modified; await this.Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = newTo }, status => status != HttpStatusCode.NoContent); result = await this.TryGetMany <MessageRedirectFromJson>("/api/redirects"); c.Response = result; return(true); }).Run(); var response = context.Response; Assert.AreEqual(1, response.Count, "Expected only 1 redirect"); Assert.AreEqual(messageRedirectId, response[0].message_redirect_id, "Message Redirect Id mismatch"); Assert.AreEqual(redirect.fromphysicaladdress, response[0].from_physical_address, "From physical address mismatch"); Assert.AreEqual(newTo, response[0].to_physical_address, "To physical address mismatch"); Assert.Greater(response[0].last_modified, context.CreatedAt, "Last modified was not updated"); }
public async Task Should_fail_validation_with_blank_tophysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var messageRedirectId = DeterministicGuid.MakeId(redirect.fromphysicaladdress.ToLowerInvariant()); await Define <Context>() .Done(async c => { await this.Post("/api/redirects", redirect); await this.Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = string.Empty }, status => status != HttpStatusCode.BadRequest); return(true); }) .Run(); }
public async Task Should_ignore_exact_copies() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var response = new List <MessageRedirectFromJson>(); await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); await this.Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); var result = await this.TryGetMany <MessageRedirectFromJson>("/api/redirects"); response = result; return(result); }).Run(); Assert.AreEqual(1, response.Count, "Expected only 1 redirect to be created"); }