|
| 1 | +using CoinbasePro.Network.HttpClient; |
| 2 | +using CoinbasePro.Services.Profiles; |
| 3 | +using CoinbasePro.Services.Profiles.Models; |
| 4 | +using CoinbasePro.Specs.JsonFixtures.Services.Profiles; |
| 5 | +using Machine.Fakes; |
| 6 | +using Machine.Specifications; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Linq; |
| 9 | +using System.Net.Http; |
| 10 | +using System.Threading.Tasks; |
| 11 | +using System; |
| 12 | +using CoinbasePro.Shared.Types; |
| 13 | + |
| 14 | +namespace CoinbasePro.Specs.Services.Profiles |
| 15 | +{ |
| 16 | + [Subject("ProductsService")] |
| 17 | + public class ProfilesServiceSpecs : WithSubject<ProfilesService> |
| 18 | + { |
| 19 | + Establish context = () => |
| 20 | + The<IHttpClient>().WhenToldTo(p => p.SendAsync(Param.IsAny<HttpRequestMessage>())) |
| 21 | + .Return(Task.FromResult(new HttpResponseMessage())); |
| 22 | + |
| 23 | + class when_getting_all_profiles |
| 24 | + { |
| 25 | + static IEnumerable<Profile> result; |
| 26 | + |
| 27 | + Establish context = () => |
| 28 | + The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>())) |
| 29 | + .Return(Task.FromResult(AllProfilesResponseFixture.Create())); |
| 30 | + |
| 31 | + Because of = () => |
| 32 | + result = Subject.GetAllProfilesAsync().Result; |
| 33 | + |
| 34 | + It should_have_correct_profiles_response_count = () => |
| 35 | + result.Count().ShouldEqual(1); |
| 36 | + |
| 37 | + It should_have_correct_profiles = () => |
| 38 | + { |
| 39 | + result.First().Id.ShouldEqual(new Guid("86602c68-306a-4500-ac73-4ce56a91d83c")); |
| 40 | + result.First().UserId.ShouldEqual("5844eceecf7e803e259d0365"); |
| 41 | + result.First().Name.ShouldEqual("default"); |
| 42 | + result.First().Active.ShouldEqual(true); |
| 43 | + result.First().IsDefault.ShouldEqual(true); |
| 44 | + result.First().CreatedAt.ShouldEqual(new DateTime(2016, 12, 9)); |
| 45 | + }; |
| 46 | + } |
| 47 | + |
| 48 | + class when_getting_a_profile_by_id |
| 49 | + { |
| 50 | + static Profile result; |
| 51 | + |
| 52 | + Establish context = () => |
| 53 | + The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>())) |
| 54 | + .Return(Task.FromResult(ProfileResponseFixture.Create())); |
| 55 | + |
| 56 | + Because of = () => |
| 57 | + result = Subject.GetProfileByIdAsync(new Guid("86602c68-306a-4500-ac73-4ce56a91d83c")).Result; |
| 58 | + |
| 59 | + It should_have_correct_profile = () => |
| 60 | + { |
| 61 | + result.Id.ShouldEqual(new Guid("86602c68-306a-4500-ac73-4ce56a91d83c")); |
| 62 | + result.UserId.ShouldEqual("5844eceecf7e803e259d0365"); |
| 63 | + result.Name.ShouldEqual("default"); |
| 64 | + result.Active.ShouldEqual(true); |
| 65 | + result.IsDefault.ShouldEqual(true); |
| 66 | + result.CreatedAt.ShouldEqual(new DateTime(2016, 12, 9)); |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + class when_creating_a_profile_transfer_on_success |
| 71 | + { |
| 72 | + static string result; |
| 73 | + |
| 74 | + Establish context = () => |
| 75 | + The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>())) |
| 76 | + .Return(Task.FromResult("OK")); |
| 77 | + |
| 78 | + Because of = () => |
| 79 | + result = Subject.CreateProfileTransferAsync( |
| 80 | + new Guid("53f58772-76e7-40d7-86bc-8155b80d7b20"), |
| 81 | + new Guid("53f58772-76e7-40d7-86bc-8155b80d7b20"), |
| 82 | + Currency.BTC, |
| 83 | + 100).Result; |
| 84 | + |
| 85 | + It should_have_returned_an_ok_response = () => |
| 86 | + result.ShouldEqual("OK"); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | + |
0 commit comments