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_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_fail_validation_with_dependent_redirects() { var toAddress = "endpointTo@machineTo"; var dependentCount = 3; var context = new Context(); Define(context); for (var i = 0; i < dependentCount; i++) { var redirect = new RedirectRequest { fromphysicaladdress = $"endpoint{i}@machine{i}", tophysicaladdress = toAddress }; await Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); } await Post("/api/redirects", new RedirectRequest { fromphysicaladdress = toAddress, tophysicaladdress = "endpointX@machineX" }, status => status != HttpStatusCode.Conflict); }
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_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_fail_validation_with_blank_tophysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = string.Empty }; Define <Context>(); await Post("/api/redirects", redirect, status => status != HttpStatusCode.BadRequest); }
public void Should_fail_validation_with_blank_fromphysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = string.Empty, tophysicaladdress = "endpointB@machine2" }; Define <Context>(); Post("/api/redirects", redirect, status => status != HttpStatusCode.BadRequest); }
public async Task Should_fail_validation_with_blank_fromphysicaladdress() { var redirect = new RedirectRequest { fromphysicaladdress = string.Empty, tophysicaladdress = "endpointB@machine2" }; 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" }; Define <Context>(); await Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); redirect.tophysicaladdress = "endpointC@machine3"; await Post("/api/redirects", redirect, status => status != HttpStatusCode.Conflict); }
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()); Define <Context>(); await Post("/api/redirects", redirect); await Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = string.Empty }, status => status != HttpStatusCode.BadRequest); }
public async Task Should_ignore_exact_copies() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; Define <Context>(); await Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); await Post("/api/redirects", redirect, status => status != HttpStatusCode.Created); var result = await TryGetMany <MessageRedirectFromJson>("/api/redirects"); List <MessageRedirectFromJson> response = result; Assert.AreEqual(1, response.Count, "Expected only 1 redirect to be created"); }
public void Should_be_successfully_deleted() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var messageRedirectId = DeterministicGuid.MakeId(redirect.fromphysicaladdress); List <MessageRedirectFromJson> response; Define <Context>(); Post("/api/redirects", redirect); Delete($"/api/redirects/{messageRedirectId}/"); TryGetMany("/api/redirects", out response); Assert.AreEqual(0, response.Count, "Expected no redirects after delete"); }
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 = new Context(); Define(context); await Post("/api/redirects", redirect); var result = await TryGetMany <MessageRedirectFromJson>("/api/redirects"); List <MessageRedirectFromJson> response = result; context.CreatedAt = response[0].last_modified; await Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = newTo }, status => status != HttpStatusCode.NoContent); result = await TryGetMany <MessageRedirectFromJson>("/api/redirects"); response = result; 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 void Should_be_added_and_accessible_via_the_api() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; List <MessageRedirectFromJson> response; Define <Context>(); Post("/api/redirects", redirect); TryGetMany("/api/redirects", out response); 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"); }