public void ShouldReturnUserInfoAfterInsert() { var apiClient = new HttpClient(_server); var userId = Guid.NewGuid(); var reqDate = DateTime.Now; var rightPostData = new SyncProfileRequest { UserId = userId, RequestId = Guid.NewGuid(), AdvertisingOptIn = true, CountryIsoCode = "US", Locale = "en-US", DateModified = reqDate, }; using (var request = RequestBuilder.CreateRequest(_url, "import.json", "application/json", HttpMethod.Post, rightPostData, new JsonMediaTypeFormatter())) using (HttpResponseMessage response = apiClient.SendAsync(request).Result) { Assert.That(response.StatusCode == HttpStatusCode.OK); } using (var proxy = new UserInfoProviderProxy(new ServiceEndpoint(ContractDescription.GetContract(typeof(IUserInfoProvider)), new BasicHttpBinding(), new EndpointAddress(Program.WcfBaseAddress)))) { var userInfo = proxy.GetUserInfo(userId); Assert.That(userInfo != null); Assert.That(userInfo.UserId == userId); Assert.That(DatesAreEqual(userInfo.DateModified, reqDate)); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); MyAccountRequestBase accountRequestBase = new SyncProfileRequest(); serializer.Populate(obj.CreateReader(), accountRequestBase); return(accountRequestBase); }
public void Save(SyncProfileRequest profile) { using (var db = new LiteDatabase(connectionString)) { var collection = db.GetCollection <SyncProfileRequest>(profilesCollection); collection.Upsert(profile); } }
public void CountryIsoCodeIsIncorrect() { var sample = new SyncProfileRequest(_correctSample1) { CountryIsoCode = "rus" }; _mockController.Post(sample); }
public void LocaleIsIncorrect() { var sample = new SyncProfileRequest(_correctSample1) { Locale = "rus-RUS" }; _mockController.Post(sample); }
public void LocaleIsNull() { var sample = new SyncProfileRequest(_correctSample1) { Locale = null }; _mockController.Post(sample); }
private Task <HttpResponseMessage> SenJsonInternal(Guid userId, string countryIsoCode, string locale) { var client = new HttpClient(); var request = new SyncProfileRequest { UserId = userId, CountryIsoCode = countryIsoCode, Locale = locale }; return(client.PostAsJsonAsync("http://localhost:51488/import.json", request)); }
public bool Upsert(SyncProfileRequest item) { using (var t = _db.BeginTrans()) { var requests = _db.GetCollection <SyncProfileRequest>("Requests"); var result = requests.Upsert(item); t.Commit(); return(result); } }
public void PostNullObject_Response_BadRequest() { SyncProfileRequest nullRequest = null; using (var client = new HttpClient()) { var response = client.PostAsJsonAsync(BaseAddress, nullRequest); Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.BadRequest); } }
public void PostUserWithNotValidLocaleISOCode_Response_BadRequest(string notValidLocalCode) { var userWithNoValidLocaleIsoCode = new SyncProfileRequest { UserId = Guid.NewGuid(), RequestId = Guid.NewGuid(), Locale = notValidLocalCode, }; using (var client = new HttpClient()) { var response = client.PostAsJsonAsync(BaseAddress, userWithNoValidLocaleIsoCode); Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.BadRequest); } }
public void PostObjectWithNullUserID_Response_NoContent() { var nullUserIdObjectRequest = new SyncProfileRequest { CountryIsoCode = "RU", AdvertisingOptIn = true }; using (var client = new HttpClient()) { var response = client.PostAsJsonAsync(BaseAddress, nullUserIdObjectRequest); Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.NoContent); } }
public IHttpActionResult Post([FromBody] SyncProfileRequest value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _profileRepository.Upsert(value); return(Ok()); } catch (Exception e) { _logger.Error(e, "Exception while upsert"); } return(InternalServerError()); }
public void ShouldReturnBadRequestOnBadLocale() { var sut = new HttpClient(_server); var rightPostData = new SyncProfileRequest { UserId = Guid.NewGuid(), RequestId = Guid.NewGuid(), AdvertisingOptIn = true, CountryIsoCode = "US", Locale = "enUS", DateModified = DateTime.Now, }; using (var request = RequestBuilder.CreateRequest(_url, "import.json", "application/json", HttpMethod.Post, rightPostData, new JsonMediaTypeFormatter())) using (HttpResponseMessage response = sut.SendAsync(request).Result) { Assert.That(response.StatusCode == HttpStatusCode.BadRequest); } }
public static void ClassInitialize(TestContext testContext) { _client = new HttpClient(); _guid = new Guid("AAAAAAAA-1111-2222-3333-000000000001"); _correctSample1 = new SyncProfileRequest() { AdvertisingOptIn = true, CountryIsoCode = "ru", DateModified = new DateTime(1800, 06, 20, 13, 00, 15), Locale = "en", RequestId = new Guid("DEADBEEF-1234-4321-7531-314159265359"), UserId = _guid }; _correctSample2 = new SyncProfileRequest() { AdvertisingOptIn = false, CountryIsoCode = "en", DateModified = new DateTime(2100, 08, 12, 11, 10, 25), Locale = "ru-RU", RequestId = new Guid("DEADBEEF-1234-4321-7531-314159265360"), UserId = _guid }; }
public IHttpActionResult Post(SyncProfileRequest request) { repository.Save(request); return(Ok()); }