Beispiel #1
0
            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));
            }
Beispiel #2
0
        public HttpResponseMessage GetByID(HttpRequestMessage request, int id)
        {
            var area = new Area();

            var result = area.Get(id);

            return request.CreateResponse(HttpStatusCode.OK, result);
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
            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();
            }
Beispiel #9
0
            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);
            }
Beispiel #10
0
 public void WhenInitialize_ShouldNotBeNull()
 {
     var subject = new Area();
     subject.Should().NotBeNull();
 }
Beispiel #11
0
            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();
            }
Beispiel #12
0
            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();
            }
Beispiel #13
0
            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();
            }
Beispiel #14
0
            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();
            }
Beispiel #15
0
        /// <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;
            }
        }
Beispiel #16
0
 public void WhenInitialize_ShouldBeActive()
 {
     var subject = new Area();
     subject.Active.Should().Be(true);
 }
Beispiel #17
0
 public void WhenInitialize_ShouldCardsListBeEmpty()
 {
     var subject = new Area();
     subject.Cards.Should().BeEmpty();
 }
Beispiel #18
0
            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();
            }
Beispiel #19
0
            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();
            }
Beispiel #20
0
            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();
            }
        }
Beispiel #22
0
            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;
                }
            }
        }
Beispiel #24
0
 public void WhenInitialize_ShouldModifiedUserBeNull()
 {
     var subject = new Area();
     subject.ModifiedUser.Should().BeNull();
 }
Beispiel #25
0
            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);
            }
Beispiel #26
0
 public void WhenInitialize_ShouldNameBeNull()
 {
     var subject = new Area();
     subject.Name.Should().BeNull();
 }
Beispiel #27
0
 public void WhenInitialize_ShouldIDBeZero()
 {
     var subject = new Area();
     subject.ID.Should().Be(0);
 }
Beispiel #28
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");
            }
Beispiel #29
0
 public void WhenInitialize_ShouldModifiedDateBeMinValue()
 {
     var subject = new Area();
     subject.ModifiedDate.Should().Be(DateTime.MinValue);
 }
Beispiel #30
0
 /// <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;
     }
 }