public void WhenNameIsNotNull_CreatedDateShouldHaveValue() { var identityProvider = new Mock<IIdentityProvider>(); identityProvider.Setup(d => d.GetUserName()).Returns("Dave Rodgers"); var NOW = new DateTime(2014, 5, 19); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.Add(It.IsAny<Area>())) .Callback<Area>(a => subject = a) .Returns(() => subject); var area = new Area(dateProvider.Object, storageProvider.Object, identityProvider.Object); var areaName = "Backlog"; subject = area.Add(areaName); subject.CreatedDate.Should().Be(new DateTime(2014, 5, 19)); }
public HttpResponseMessage GetByID(HttpRequestMessage request, int id) { var area = new Area(); var result = area.Get(id); return request.CreateResponse(HttpStatusCode.OK, result); }
public HttpResponseMessage Delete(HttpRequestMessage request, int id) { var area = new Area(); area.Remove(id); return request.CreateResponse(HttpStatusCode.NoContent); }
public Area Add(Area area) { using (var db = new CardsDBContext()) { var result = db.Areas.Add(area); db.SaveChanges(); return result; } }
public HttpResponseMessage Add(HttpRequestMessage request, Area area) { var result = area.Add(area.Name); if (result != null) { return request.CreateResponse(HttpStatusCode.Created, result); } else { return request.CreateResponse(HttpStatusCode.InternalServerError); } }
public HttpResponseMessage Edit(HttpRequestMessage request, int id, Area area) { area.ID = id; var result = area.Update(area); if (result != null) { return request.CreateResponse(HttpStatusCode.Created, result); } else { return request.CreateResponse(HttpStatusCode.InternalServerError); } }
public HttpResponseMessage Edit(HttpRequestMessage request, int id, Area area) { Card card = new Card(); var result = card.Move(id, area); if (result != null) { return request.CreateResponse(HttpStatusCode.OK, result); } else { return request.CreateResponse(HttpStatusCode.InternalServerError); } }
public void WhenEdit_ShouldNotBeNull() { var identityProvider = new Mock<IIdentityProvider>(); identityProvider.Setup(d => d.GetUserName()).Returns("Dave Rodgers"); var NOW = new DateTime(2014, 5, 20); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.GetArea(It.Is<int>(i => i == 1))) .Returns(() => new Area() { ID = 1, Name = "Backlog", CreatedDate = NOW }); storageProvider .Setup(d => d.Update(It.IsAny<Area>())) .Callback<Area>(a => subject = a.ID == 1 ? a : null) .Returns(() => subject); var area = new Area(dateProvider.Object, storageProvider.Object, identityProvider.Object); subject = area.Get(1); subject.Name = "Not a Backlog"; subject = area.Update(subject); subject.Should().NotBeNull(); }
public void WhenGetAll_AndWithNewArea_StatusShouldBeActive() { var storageProvider = new Mock<IStorageProvider>(); storageProvider.Setup(d => d.GetAllAreas()).Returns( () => { List<Area> toReturn = new List<Area>(); toReturn.Add(new Area()); toReturn.Add(new Area()); return toReturn; }); var area = new Area(null, storageProvider.Object, null); var subject = area.GetAll(); subject.Should().OnlyContain(item=>item.Active == true); }
public void WhenInitialize_ShouldNotBeNull() { var subject = new Area(); subject.Should().NotBeNull(); }
public void WhenEdit_ShouldBeNull() { var NOW = new DateTime(2014, 5, 20); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.Update(It.IsAny<Area>())) .Callback<Area>(a => subject = a) .Returns(() => null); var area = new Area(dateProvider.Object, storageProvider.Object, null); subject = area.Update(null); subject.Should().BeNull(); }
public void WhenNameIsNotNull_ShouldNotBeNull() { //Arrange var identityProvider = new Mock<IIdentityProvider>(); identityProvider.Setup(d => d.GetUserName()).Returns("Dave Rodgers"); var NOW = DateTime.Now; var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.Add(It.IsAny<Area>())) .Callback<Area>(a => subject = a) .Returns(() => subject); var area = new Area(dateProvider.Object, storageProvider.Object, identityProvider.Object); var areaName = "Backlog"; //Act subject = area.Add(areaName); //Assert subject.Should().NotBeNull(); }
public void WhenGet_CardsShouldNotBeEmpty() { var NOW = new DateTime(2014, 5, 19); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.GetArea(It.Is<int>(i => i == 1))) .Returns(() => new Area() { ID = 1, CreatedDate = NOW, ModifiedUser = "******", Cards = new List<Card>() { new Card(), new Card() }}); var area = new Area(dateProvider.Object, storageProvider.Object, null); subject = area.Get(1); subject.Cards.Should().NotBeEmpty(); }
public void WhenGetAll_ShouldNotBeNull() { var storageProvider = new Mock<IStorageProvider>(); List<Area> subject = null; storageProvider .Setup(d => d.GetAllAreas()) .Returns(() => new List<Area>()); var area = new Area(null, storageProvider.Object, null); subject = area.GetAll(); subject.Should().NotBeNull(); }
/// <summary> /// Moves the card with the specified identifier to the target area. /// </summary> /// <param name="id">The identifier.</param> /// <param name="targetArea">The target area.</param> /// <returns></returns> public Card Move(int id, Area targetArea) { var card = Get(id); if (card != null) { card.AreaID = targetArea.ID; return onUpdate(card, CardActivityType.Move); } else { return null; } }
public void WhenInitialize_ShouldBeActive() { var subject = new Area(); subject.Active.Should().Be(true); }
public void WhenInitialize_ShouldCardsListBeEmpty() { var subject = new Area(); subject.Cards.Should().BeEmpty(); }
public void WhenDelete_DataShouldBeRemoved() { var identityProvider = new Mock<IIdentityProvider>(); identityProvider.Setup(d => d.GetUserName()).Returns("Dave Rodgers"); var NOW = new DateTime(2014, 5, 20); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.RemoveArea(It.IsAny<Area>())); storageProvider .Setup(d => d.GetArea(It.Is<int>(i => i == 1))) .Returns(() => null); var area = new Area(dateProvider.Object, storageProvider.Object, identityProvider.Object); area.Remove(1); subject = area.Get(1); subject.Should().BeNull(); }
public void WhenGet_ShouldNotBeNull() { var NOW = DateTime.Now; var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.GetArea(It.Is<int>(i => i == 1))) .Returns(() => new Area() { ID = 1, Name = "Backlog", CreatedDate = NOW }); var area = new Area(dateProvider.Object, storageProvider.Object, null); subject = area.Get(1); subject.Should().NotBeNull(); }
public void WhenGet_ShouldBeNull() { var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.GetArea(It.IsAny<int>())) .Returns(() => null); var area = new Area(null, storageProvider.Object, null); var id = 1; subject = area.Get(id); subject.Should().BeNull(); }
public void RemoveArea(Area area) { using (var db = new CardsDBContext()) { var itemToDelete = db.Areas.FirstOrDefault(item => item.ID == area.ID); itemToDelete.ModifiedDate = area.ModifiedDate; itemToDelete.ModifiedUser = area.ModifiedUser; itemToDelete.Active = false; db.SaveChanges(); } }
public void WhenNameIsNotNull_IDShouldBeOne() { var identityProvider = new Mock<IIdentityProvider>(); identityProvider.Setup(d => d.GetUserName()).Returns("Dave Rodgers"); var NOW = DateTime.Now; var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.Add(It.IsAny<Area>())) .Callback<Area>(a => { a.ID = 1; subject = a; }).Returns(() => subject); var area = new Area(dateProvider.Object, storageProvider.Object, identityProvider.Object); var areaName = "Backlog"; subject = area.Add(areaName); subject.ID.Should().Be(1); }
public Area Update(Area area) { using (var db = new CardsDBContext()) { var areaToUpdate = db.Areas.FirstOrDefault(item => item.ID == area.ID); if (areaToUpdate != null) { areaToUpdate.Name = area.Name; areaToUpdate.ModifiedDate = area.ModifiedDate; areaToUpdate.ModifiedUser = area.ModifiedUser; db.SaveChanges(); return areaToUpdate; } else { return null; } } }
public void WhenInitialize_ShouldModifiedUserBeNull() { var subject = new Area(); subject.ModifiedUser.Should().BeNull(); }
public void WhenGetAll_AndWithNewArea_ShouldHaveOneElement() { var storageProvider = new Mock<IStorageProvider>(); storageProvider.Setup(d => d.GetAllAreas()).Returns( () => { List<Area> toReturn = new List<Area>(); toReturn.Add(new Area()); return toReturn; }); var area = new Area(null, storageProvider.Object, null); var subject = area.GetAll(); subject.Count.Should().Be(1); }
public void WhenInitialize_ShouldNameBeNull() { var subject = new Area(); subject.Name.Should().BeNull(); }
public void WhenInitialize_ShouldIDBeZero() { var subject = new Area(); subject.ID.Should().Be(0); }
public void WhenGet_ModifiedUserShouldHaveValue() { var NOW = new DateTime(2014, 5, 19); var dateProvider = new Mock<IDateProvider>(); dateProvider.Setup(d => d.Now()).Returns(NOW); var storageProvider = new Mock<IStorageProvider>(); Area subject = null; storageProvider .Setup(d => d.GetArea(It.Is<int>(i => i == 1))) .Returns(() => new Area() { ID = 1, CreatedDate = NOW, ModifiedUser = "******" }); var area = new Area(dateProvider.Object, storageProvider.Object, null); subject = area.Get(1); subject.ModifiedUser.Should().Be("Dave Rodgers"); }
public void WhenInitialize_ShouldModifiedDateBeMinValue() { var subject = new Area(); subject.ModifiedDate.Should().Be(DateTime.MinValue); }
/// <summary> /// Updates the specified area. /// </summary> /// <param name="area">The area.</param> /// <returns></returns> public Area Update(Area area) { if (area != null) { area.ModifiedUser = IdentityProvider.GetUserName(); area.ModifiedDate = DateProvider.Now(); return StorageProvider.Update(area); } else { return null; } }