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

            var result = area.Get(id);

            return request.CreateResponse(HttpStatusCode.OK, result);
        }
示例#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;
            }
        }
示例#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);
            }
        }
示例#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);
            }
        }
示例#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);
            }
        }
示例#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();
            }
示例#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);
            }
示例#10
0
 public void WhenInitialize_ShouldNotBeNull()
 {
     var subject = new Area();
     subject.Should().NotBeNull();
 }
示例#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();
            }
示例#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();
            }
示例#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();
            }
示例#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();
            }
示例#15
0
文件: Card.cs 项目: netxph/cards-tfs
        /// <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;
            }
        }
示例#16
0
 public void WhenInitialize_ShouldBeActive()
 {
     var subject = new Area();
     subject.Active.Should().Be(true);
 }
示例#17
0
 public void WhenInitialize_ShouldCardsListBeEmpty()
 {
     var subject = new Area();
     subject.Cards.Should().BeEmpty();
 }
示例#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();
            }
示例#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();
            }
示例#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();
            }
        }
示例#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;
                }
            }
        }
示例#24
0
 public void WhenInitialize_ShouldModifiedUserBeNull()
 {
     var subject = new Area();
     subject.ModifiedUser.Should().BeNull();
 }
示例#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);
            }
示例#26
0
 public void WhenInitialize_ShouldNameBeNull()
 {
     var subject = new Area();
     subject.Name.Should().BeNull();
 }
示例#27
0
 public void WhenInitialize_ShouldIDBeZero()
 {
     var subject = new Area();
     subject.ID.Should().Be(0);
 }
示例#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");
            }
示例#29
0
 public void WhenInitialize_ShouldModifiedDateBeMinValue()
 {
     var subject = new Area();
     subject.ModifiedDate.Should().Be(DateTime.MinValue);
 }
示例#30
0
文件: Area.cs 项目: netxph/cards-tfs
 /// <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;
     }
 }