public void When_InvalidId_Expect_Throws() { var dataStore = new SkillsDataStore(); const int id = 1; Assert.Throws <NotFoundException>(() => dataStore.Update(id, new Skill())); }
public void When_ItemFound_OverwritesProperties() { const string originalName = "name"; const string newName = "newName"; const int originalRating = 10; const int newRating = 20; var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var original = new Skill { Name = originalName, Rating = originalRating }; var id = GetOkResultValue(controller.Post(original)).Id; var updated = new Skill { Name = newName, Rating = newRating }; var result = GetOkResultValue(controller.Post(id, updated)); // Checking properties one by one is OK as long as they are few and stable. // For a more complex object, I'd consider using reflection to ensure that the test // automatically picks up any added properties. Assert.Equal(newName, result.Name); Assert.Equal(newRating, result.Rating); var result2 = (Skill)((OkObjectResult)controller.Get(id)).Value; Assert.Equal(newName, result2.Name); Assert.Equal(newRating, result2.Rating); }
public void When_AddingFirstItem_Returns_ItemWithId_1() { var dataStore = new SkillsDataStore(); var result = dataStore.Add(new Skill()); Assert.Equal(1, result.Id); }
public void When_OneSkillAdded_Returns_OneSkill() { var dataStore = new SkillsDataStore(); dataStore.Add(new Skill()); var skills = dataStore.Get(); Assert.Single(skills); }
public void When_ValidId_Expect_RemovesValue() { var dataStore = new SkillsDataStore(); var result = dataStore.Add(new Skill()); var id = result.Id; dataStore.Remove(id); Assert.Throws <NotFoundException>(() => dataStore.Get(id)); }
public void When_AddingMultipleItems_Returns_ItemsWithIncreasingId() { var dataStore = new SkillsDataStore(); for (var i = 0; i < 5; i++) { var result = dataStore.Add(new Skill()); Assert.Equal(i + 1, result.Id); } }
public void When_ValidId_Returns_Item_WithThatId() { var dataStore = new SkillsDataStore(); dataStore.Add(new Skill()); var skill = dataStore.Get(1); Assert.Equal(skill.Id, 1); }
public void When_TwoSkillsAdded_Returns_TwoSkills() { var dataStore = new SkillsDataStore(); dataStore.Add(new Skill()); dataStore.Add(new Skill()); var skills = dataStore.Get(); Assert.Collection(skills, s => {; }, s => {; }); }
public void When_ValidId_Expect_Returns_ItemWithId() { var dataStore = new SkillsDataStore(); var skill1 = dataStore.Add(new Skill()); var skill2 = new Skill(); var id = skill1.Id; var actual = dataStore.Update(id, skill2); Assert.Equal(skill2.Id, id); }
public void When_ItemNotFound_Returns_NotFound() { var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var id = GetOkResultValue(controller.Post(new Skill())).Id; var result = controller.Post(id + 1, new Skill()); Assert.IsType(typeof(NotFoundResult), result); }
public void When_ValidId_Expect_ReplacesValue() { var dataStore = new SkillsDataStore(); var skill1 = dataStore.Add(new Skill()); var skill2 = new Skill(); var id = skill1.Id; dataStore.Update(id, skill2); var actual = dataStore.Get(id); Assert.Equal(skill2, actual); }
public void When_ItemHasBeenRemoved_Expect_DoesNotReuseId() { var dataStore = new SkillsDataStore(); var skill1 = dataStore.Add(new Skill()); var skill2 = dataStore.Add(new Skill()); dataStore.Remove(skill1.Id); var skill3 = dataStore.Add(new Skill()); Assert.Equal(3, skill3.Id); }
public void When_InvalidId_Returns_NotFound() { const int id = 1; var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var updated = new Skill { Name = "updated", Rating = 2 }; var result = controller.Put(id, updated); Assert.IsType(typeof(NotFoundResult), result); }
public void When_ItemFound_AndNewNameIsEmpty_KeepsOriginalName() { const string originalName = "name"; const string newName = ""; var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var original = new Skill { Name = originalName }; var id = GetOkResultValue(controller.Post(original)).Id; var updated = new Skill { Name = newName }; var result = GetOkResultValue(controller.Post(id, updated)); Assert.Equal(originalName, result.Name); }
public void When_ItemFound_AndNewRatingIsZero_KeepsOriginalRating() { const int originalRating = 22; const int newRating = 0; var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var original = new Skill { Rating = originalRating }; var id = GetOkResultValue(controller.Post(original)).Id; var updated = new Skill { Rating = newRating }; var result = GetOkResultValue(controller.Post(id, updated)); Assert.Equal(originalRating, result.Rating); }
public void When_ValidId_StoresItem() { var original = new Skill { Name = "original", Rating = 1 }; var dataStore = new SkillsDataStore(); var controller = new SkillsController(dataStore); var id = GetOkResultValue(controller.Post(original)).Id; var updated = new Skill { Name = "updated", Rating = 2 }; controller.Put(id, updated); var result = GetOkResultValue(controller.Get(id)); Assert.Equal(updated.Name, result.Name); Assert.Equal(updated.Rating, result.Rating); }
public void When_InvalidId_Expect_Throws() { var dataStore = new SkillsDataStore(); Assert.Throws <NotFoundException>(() => dataStore.Get(1)); }
public void When_NothingAdded_Returns_EmptyList() { var skills = new SkillsDataStore().Get(); Assert.Empty(skills); }