public void RetrievingACustomerAddressByType(JArray addresses) { const int CustomerId = 346760; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((int customerId, AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where n.Value<int>("OwnerId") == customerId && addressFilter.Type.Contains(n.Value<string>("Type")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'address type for a customer' request is sent". f(() => { Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "?Type=" + this.AddressTypes[1])).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1]))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then an address is returned". f(() => addresses.Count().ShouldEqual(1)); "Then each address references the queried customer". f(() => addresses.ToList().ForEach(address => CustomerId.ShouldEqual(address.Value<int>("OwnerId")))); "Then each address references the queried type". f(() => addresses.ToList().ForEach(address => address.Value<string>("Type").ShouldEqual(this.AddressTypes[1]))); }
public void RetrievingAllAddressesForOwnerIds(JArray addresses) { const int OwnerId1 = 346760; const int OwnerId2 = 42165; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2)))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where addressFilter.OwnerId.Contains(n.Value<int>("OwnerId")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses for multiple owner ids' request is sent". f(() => { Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerId=" + OwnerId1 + "&OwnerId=" + OwnerId2)).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then the expected addresses are returned". f(() => addresses.Count().ShouldEqual(4)); "Then each address references a queried owner". f(() => addresses.ToList().ForEach(address => new int[] { OwnerId1, OwnerId2 }.ShouldContain(address.Value<int>("OwnerId")))); }
public void RetrievingAddressesByCity(JArray addresses) { const string City = "Denver"; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where n.Value<string>("City").ToLowerInvariant().Contains(City.ToLowerInvariant()) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses by city' request is sent". f(() => { Response = Client.GetAsync(_addressesUri + "/?City=" + City).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City)))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then addresses are returned". f(() => addresses.Count().ShouldEqual(3)); "Then each address's city references the queried city". f(() => addresses.ToList().ForEach(address => address.Value<string>("City").ToLowerInvariant().ShouldContain(City.ToLowerInvariant()))); }
public void RetrievingCustomerAddressesByZipCode(JArray addresses) { const int CustomerId = 346760; const string ZipCode = "802"; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))).Returns((int customerId, AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where n.Value<string>("ZipCode").Contains(addressFilter.Zip) && n.Value<int>("OwnerId") == CustomerId select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses for a customer by zip code' request is sent". f(() => { Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "/?Zip=" + ZipCode)).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then addresses are returned". f(() => addresses.Count().ShouldEqual(2)); "Then the address references the queried customer". f(() => addresses.First().Value<int>("OwnerId").ShouldEqual(CustomerId)); "Then each address references the queried zip code". f(() => addresses.ToList().ForEach(address => address.Value<string>("ZipCode").ShouldContain(ZipCode))); }
public void RetrievingAllCustomerAddresses(JArray addresses) { const int CustomerId = 346760; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.IsAny<AddressesFilter>())).Returns((int customerId, AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where customerId == n.Value<int>("OwnerId") select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'all addresses for a customer' request is sent". f(() => { Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId))).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.IsAny<AddressesFilter>()))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then all addresses are returned for the owner". f(() => addresses.Count().ShouldEqual(3)); "Then each address references the expected owner id". f(() => addresses.ToList().ForEach(address => address.Value<int>("OwnerId").ShouldEqual(CustomerId))); }
public void RetrievingAnAddressTypeForAnOwner(JArray addresses) { const int OwnerIdTest = 346760; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerIdTest) && addressFilter.Type.Contains(this.AddressTypes[2])))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where addressFilter.OwnerId.Contains(n.Value<int>("OwnerId")) && addressFilter.Type.Contains(n.Value<string>("Type")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'address for owner id and type' request is sent". f(() => { Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerId=" + OwnerIdTest + "&Type=" + this.AddressTypes[2])).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerIdTest) && addressFilter.Type.Contains(this.AddressTypes[2]))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then an address is returned". f(() => addresses.Count().ShouldEqual(1)); "Then the address references the queried owner id". f(() => addresses.ToList().ForEach(address => OwnerIdTest.ShouldEqual(address.Value<int>("OwnerId")))); "Then the address references the queried type". f(() => addresses.ToList().ForEach(address => address.Value<string>("Type").ShouldEqual(this.AddressTypes[2]))); }
public void RetrievingAllAddressesForOwnerTypes(JArray addresses) { string[] ownerType = { "BUS", "PER" }; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerType.Contains(ownerType[0]) && addressFilter.OwnerType.Contains(ownerType[1])))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where addressFilter.OwnerType.Contains(n.Value<string>("OwnerType")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses for multiple owner types' request is sent". f(() => { Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerType=" + ownerType[0] + "&OwnerType=" + ownerType[1])).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerType.Contains(ownerType[0]) && addressFilter.OwnerType.Contains(ownerType[1]))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then the expected addresses are returned". f(() => addresses.Count().ShouldEqual(9)); "Then each address references a queried owner type". f(() => addresses.ToList().ForEach(address => new string[] { ownerType[0], ownerType[1] }.ShouldContain(address.Value<string>("OwnerType")))); }
public void RetrievingAllAddressesForOwnerName(JArray addresses) { const string OwnerNameTest = "THE DILLION COMPANY"; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest)))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where addressFilter.OwnerName.Contains(n.Value<string>("OwnerName")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'all addresses for owner name' request is sent". f(() => { Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerName=" + OwnerNameTest)).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then all addresses are returned for the queried owner name". f(() => addresses.Count().ShouldEqual(3)); "Then each address references the expected owner name". f(() => addresses.ToList().ForEach(address => address.Value<string>("OwnerName").ShouldEqual(OwnerNameTest))); }
public void RetrievingAddressesByTypes(JArray addresses) { "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[0]) && addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where addressFilter.Type.Contains(n.Value<string>("Type")) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses by multiple types' request is sent". f(() => { Response = Client.GetAsync(_addressesUri + "/?Type=" + this.AddressTypes[0] + "&Type=" + this.AddressTypes[1]).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1]) && addressFilter.Type.Contains(this.AddressTypes[1]))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then addresses are returned". f(() => addresses.Count().ShouldEqual(6)); "Then each address references a queried type". f(() => addresses.ToList().ForEach(address => new string[] { this.AddressTypes[0], this.AddressTypes[1] }.Contains(address.Value<string>("Type")))); }
public void RetrievingAddressesByStreet2(JArray addresses) { const string Street2 = "VOGELWEIHERSTR"; "Given existing addresses". f(() => { MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2)))).Returns((AddressesFilter addressFilter) => { var filteredAddresses = from n in this.FakeAddresses where n.Value<string>("Street2") != null && n.Value<string>("Street2").Contains(addressFilter.Street2) select n; return Task.FromResult<dynamic>(filteredAddresses); }); }); "When a GET 'addresses by street2' request is sent". f(() => { Response = Client.GetAsync(_addressesUri + "/?Street2=" + Street2).Result; }); "Then the request is received by the API Controller". f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2))))); "Then a response is received by the HTTP client". f(() => { Response.Content.ShouldNotBeNull(); }); "Then content should be returned". f(() => { addresses = Response.Content.ReadAsAsync<JArray>().Result; addresses.ShouldNotBeNull(); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then addresses are returned". f(() => addresses.Count().ShouldEqual(1)); "Then each address references the queried street2". f(() => addresses.ToList().ForEach(address => address.Value<string>("Street2").ShouldContain(Street2))); }
private JObject ArrayDiff(JArray left, JArray right) { var result = JObject.Parse(@"{ ""_t"": ""a"" }"); int commonHead = 0; int commonTail = 0; if (JToken.DeepEquals(left, right)) return null; // Find common head while (commonHead < left.Count() && commonHead < right.Count() && JToken.DeepEquals(left[commonHead], right[commonHead])) { commonHead++; } // Find common tail while (commonTail + commonHead < left.Count() && commonTail + commonHead < right.Count() && JToken.DeepEquals(left[left.Count() - 1 - commonTail], right[right.Count() - 1 - commonTail])) { commonTail++; } if (commonHead + commonTail == left.Count()) { // Trivial case, a block (1 or more consecutive items) was added for (int index = commonHead; index < right.Count() - commonTail; ++index) { result[$"{index}"] = new JArray(right[index]); } return result; } if (commonHead + commonTail == right.Count()) { // Trivial case, a block (1 or more consecutive items) was removed for (int index = commonHead; index < left.Count() - commonTail; ++index) { result[$"_{index}"] = new JArray(left[index], 0, (int)DiffOperation.Deleted); } return result; } // Complex Diff, find the LCS (Longest Common Subsequence) List<JToken> trimmedLeft = left.ToList().GetRange(commonHead, left.Count() - commonTail - commonHead); List<JToken> trimmedRight = right.ToList().GetRange(commonHead, right.Count() - commonTail - commonHead); Lcs lcs = Lcs.Get(trimmedLeft, trimmedRight); for (int index = commonHead; index < left.Count() - commonTail; ++index) { if (lcs.Indices1.IndexOf(index - commonHead) < 0) { // Removed result[$"_{index}"] = new JArray(left[index], 0, (int)DiffOperation.Deleted); } } for (int index = commonHead; index < right.Count() - commonTail; index++) { var indexRight = lcs.Indices2.IndexOf(index - commonHead); if (indexRight < 0) { // Added result[$"{index}"] = new JArray(right[index]); } else { var li = lcs.Indices1[indexRight] + commonHead; var ri = lcs.Indices2[indexRight] + commonHead; JToken diff = Diff(left[li], right[ri]); if (diff != null) { result[$"{index}"] = diff; } } } return result; }