public async Task UpdateCalendarEvent_ShouldReturnNotFound( int id, string color, string title, string description, string start, string end = null ) { CalendarEventInputModel inputModel = new CalendarEventInputModel { Color = color, Title = title, Description = description, Start = DateTime.Parse(start), End = end == null ? default(DateTime) : DateTime.Parse(end) }; var json = JsonConvert.SerializeObject(inputModel); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var response = await _client.PutAsync($"/api/calendar/events/{id}", stringContent); var stringResponse = await response.Content.ReadAsStringAsync(); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task UpateCalendarEvent_ShouldReturnNoContentResult( int id, string color, string title, string description, string start, string end = null) { // Arrange CalendarEventInputModel inputModel = new CalendarEventInputModel { Color = color, Title = title, Description = description, Start = DateTime.Parse(start), End = end == null ? default(DateTime?) : DateTime.Parse(end) }; var json = JsonConvert.SerializeObject(inputModel); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // Act var response = await _client.PutAsync($"/api/calendar/events/{id}", stringContent); response.EnsureSuccessStatusCode(); // Assert response.StatusCode.Should().Be(HttpStatusCode.NoContent); // Check updated data await GetCalendarEvent_ById_ShouldReturnEvent(id, color, title, description, start, end); }
public IActionResult Post([FromBody] CalendarEventInputModel item) { if (item == null) { return(BadRequest()); } // replace with command pattern or builder pattern var newItem = CalendarEvent.Create( item.Color, item.Title, item.Description, item.Start, item.End); if (item.Reminders != null) { newItem.WithReminder( Reminder.Create( item.Reminders.ToArray()[0].Active, item.Reminders.ToArray()[0].Time, item.Reminders.ToArray()[0].TimeOffset)); } _calendarService.Store(newItem); return(Ok()); }
public async Task PostCalendarEvent_WithReminder_ShouldReturnNoContentResult( string color, string title, string description, string start, string end, string reminderTime, bool isReminderActive, ReminderTimeOffset reminderTimeOffset) { // Arrange CalendarEventInputModel inputModel = new CalendarEventInputModel { Color = color, Title = title, Description = description, Start = DateTime.Parse(start), End = end == null ? default(DateTime) : DateTime.Parse(end), Reminders = new List <ReminderInputModel> { new ReminderInputModel { Time = DateTime.Parse(reminderTime), Active = isReminderActive, TimeOffset = reminderTimeOffset } } }; var json = JsonConvert.SerializeObject(inputModel); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // Act var response = await _client.PostAsync($"/api/calendar/events/", stringContent); response.EnsureSuccessStatusCode(); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); }
public IActionResult Put(int id, [FromBody] CalendarEventInputModel item) { // Guards if (item == null) { return(BadRequest()); } var existingItem = _calendarService.GetById(id); if (existingItem == null) { return(NotFound()); } var mappedItem = _mapper.Map <CalendarEvent>(item); mappedItem.Id = id; // Update logic _calendarService.Update(mappedItem); // Return update ok result return(NoContent()); }