Ejemplo n.º 1
0
        public async void BugService_When_UpdateBugIsCalledWithAnIdThatExistsAndUpdateBugCalledOnRepositoryFails_Then_FalseIsReturned()
        {
            var newBugData = new Bug
            {
                Id          = "123",
                Title       = "Updated Title",
                Description = "Updated description",
                ClosedOn    = DateTime.Now,
                Status      = Status.Closed,
                AssignedTo  = "User",
                ReportedBy  = "User",
                ReportedOn  = DateTime.Now,
                Severity    = Severity.High
            };
            var existingBugData = new Bug
            {
                Id          = "123",
                Title       = "Existing Title",
                Description = "Existing description",
                ClosedOn    = DateTime.MinValue,
                Status      = Status.Opened,
                AssignedTo  = "",
                ReportedBy  = "",
                ReportedOn  = DateTime.MinValue,
                Severity    = Severity.Low
            };

            _repository.Setup(_ => _.Find(newBugData.Id)).ReturnsAsync(existingBugData);
            _repository.Setup(_ => _.Update(existingBugData)).ReturnsAsync(false);
            var service = new BugService(_repository.Object);

            var result = await service.UpdateBug(newBugData);

            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void BugService_When_UpdateBugIsCalledWithAEmptySpaceId_Then_ApplicationExceptionIsThrown()
        {
            var bug = new Bug {
                Id = " "
            };

            var service = new BugService(_repository.Object);

            Assert.ThrowsAsync <ApplicationException>(() => service.UpdateBug(bug));
        }
Ejemplo n.º 3
0
        public void BugService_When_UpdateBugIsCalledWithAnIdThatDoesntExist_Then_ApplicationExceptionIsThrown()
        {
            var bug = new Bug {
                Id = "123"
            };
            Bug nullBug = null;

            _repository.Setup(_ => _.Find(bug.Id)).ReturnsAsync(nullBug);
            var service = new BugService(_repository.Object);

            Assert.ThrowsAsync <ApplicationException>(() => service.UpdateBug(bug));
        }
Ejemplo n.º 4
0
        public async void BugService_When_UpdateBugIsCalledWithAnIdThatExistsAndUpdateBugIsCalledOnRepositorySuccessfullyAndAssignedToIsntChangedThen_TrueIsReturned()
        {
            var newBugData = new Bug
            {
                Id          = "123",
                Title       = "Updated Title",
                Description = "Updated description",
                ClosedOn    = DateTime.Now,
                Status      = Status.Closed,
                AssignedTo  = "User",
                ReportedBy  = "User",
                ReportedOn  = DateTime.Now,
                Severity    = Severity.High
            };
            var existingBugData = new Bug
            {
                Id          = "123",
                Title       = "Existing Title",
                Description = "Existing description",
                ClosedOn    = DateTime.MinValue,
                Status      = Status.Opened,
                AssignedTo  = "User",
                ReportedBy  = "",
                ReportedOn  = DateTime.MinValue,
                Severity    = Severity.Low
            };

            _repository.Setup(_ => _.Find(newBugData.Id)).ReturnsAsync(existingBugData);
            _repository.Setup(_ => _.Update(existingBugData)).ReturnsAsync(true);
            var service = new BugService(_repository.Object);

            var result = await service.UpdateBug(newBugData);

            Assert.Equal(newBugData.Id, existingBugData.Id);
            Assert.Equal(newBugData.Title, existingBugData.Title);
            Assert.Equal(newBugData.Description, existingBugData.Description);
            Assert.Equal(newBugData.ClosedOn, existingBugData.ClosedOn);
            Assert.Equal(newBugData.Status, existingBugData.Status);
            Assert.Equal(newBugData.AssignedTo, existingBugData.AssignedTo);
            Assert.Equal(newBugData.ReportedBy, existingBugData.ReportedBy);
            Assert.Equal(newBugData.ReportedOn, existingBugData.ReportedOn);
            Assert.Equal(newBugData.Severity, existingBugData.Severity);

            Assert.True(result);
        }