Exemplo n.º 1
0
        public void Update_ShouldValidate_WhenUpdateWorker()
        {
            //Arrange
            var provider      = base.BuildServiceProvider();
            var workerService = provider.GetService <IWorkerService>();
            var controller    = new DownTimeAlerterController(workerService);

            var createModel = new DownTimeAlerterViewModel()
            {
                Name             = "test",
                Email            = "*****@*****.**",
                Interval         = 1000,
                Url              = "google.com",
                NotificationType = (int)NotificationType.Email
            };

            var updateModel = new DownTimeAlerterViewModel()
            {
                Name             = "test2",
                Email            = "*****@*****.**",
                Interval         = 2000,
                Url              = "google.com",
                NotificationType = (int)NotificationType.Email
            };

            //Act
            controller.Create(createModel);
            controller.Update(createModel.Name, updateModel);

            //Assert
            Assert.AreEqual(1, workerService.List().Count());
            Assert.AreEqual(updateModel.Name, workerService.Get(updateModel.Name).Name);
        }
Exemplo n.º 2
0
        public void Delete_ShouldNotValidate_WhenWorkerNameIsNull()
        {
            //Arrange
            var workerMock = new Mock <IWorkerService>();

            workerMock.Setup(x => x.Remove(It.IsAny <string>()));
            var controller = new DownTimeAlerterController(workerMock.Object);

            //Act
            controller.Delete(It.IsAny <string>());

            //Assert
            workerMock.Verify(x => x.Remove(It.IsAny <string>()), Times.Never);
        }
Exemplo n.º 3
0
        public void Update_ShouldNotValidate_WhenWorkerNameIsNull()
        {
            //Arrange
            var workerMock = new Mock <IWorkerService>();

            workerMock.Setup(x => x.Update(It.IsAny <string>(), It.IsAny <WorkerDto>()));
            var controller = new DownTimeAlerterController(workerMock.Object);

            controller.ModelState.AddModelError("test", "test error");

            //Act
            controller.Update(It.IsAny <string>(), new DownTimeAlerterViewModel());

            //Assert
            workerMock.Verify(x => x.Update(It.IsAny <string>(), It.IsAny <WorkerDto>()), Times.Never);
            Assert.IsFalse(controller.ModelState.IsValid);
        }
Exemplo n.º 4
0
        public void Delete_ShouldValidate_WhenDeleteWorker()
        {
            //Arrange
            var provider      = base.BuildServiceProvider();
            var workerService = provider.GetService <IWorkerService>();
            var controller    = new DownTimeAlerterController(workerService);

            var createModel = new DownTimeAlerterViewModel()
            {
                Name             = "test",
                Email            = "*****@*****.**",
                Interval         = 1000,
                Url              = "google.com",
                NotificationType = (int)NotificationType.Email
            };


            //Act
            controller.Create(createModel);
            controller.Delete(createModel.Name);

            //Assert
            Assert.IsNull(workerService.Get(createModel.Name));
        }