public void DeleteLanguage_Action_Fails()
        {
            // Arrange
            var languageDto = TestHelper.LanguageDto();

            GenericServiceResponse <bool> fakeResponse = null;

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.LanguageService.DeleteLanguage(languageDto)).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericViewModel();

            var action = new DeleteLanguage <GenericViewModel>(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke(languageDto);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericViewModel));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 1);
            Assert.IsTrue(result.HasErrors);
            Assert.IsNotNull(result.Success);
            Assert.IsInstanceOfType(result.Success, typeof(bool));
            Assert.IsFalse(result.Success);
        }
Ejemplo n.º 2
0
        public void Should_set_language_status_to_deleted()
        {
            var language      = new Language();
            var command       = new DeleteLanguage();
            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            language.Delete(command, validatorMock.Object);

            Assert.AreEqual(true, language.Status == LanguageStatus.Deleted);
        }
Ejemplo n.º 3
0
        public void Should_throw_exception_when_already_deleted()
        {
            var language      = new Language();
            var command       = new DeleteLanguage();
            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            language.Delete(command, validatorMock.Object);

            Assert.Throws <Exception>(() => language.Delete(command, validatorMock.Object));
        }
Ejemplo n.º 4
0
        public void Should_call_validator()
        {
            var language      = new Language();
            var command       = new DeleteLanguage();
            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            language.Delete(command, validatorMock.Object);

            validatorMock.Verify(x => x.Validate(command));
        }
Ejemplo n.º 5
0
        public void Should_have_validation_error_when_site_id_is_empty()
        {
            var command = new DeleteLanguage
            {
                SiteId = Guid.Empty,
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();
            var validator     = new DeleteLanguageValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
Ejemplo n.º 6
0
        public void Should_throw_exception_if_language_is_deleted()
        {
            var deleteLanguageCommand = new DeleteLanguage
            {
                SiteId = _language.SiteId,
                Id     = _language.Id
            };
            var deleteLanguageValidatorMock = new Mock <IValidator <DeleteLanguage> >();

            deleteLanguageValidatorMock.Setup(x => x.Validate(deleteLanguageCommand)).Returns(new ValidationResult());
            _language.Delete(deleteLanguageCommand, deleteLanguageValidatorMock.Object);
            Assert.Throws <Exception>(() => _language.Reorder(1));
        }
Ejemplo n.º 7
0
        public void Should_set_site_id_in_language_deleted_event()
        {
            var language      = new Language();
            var command       = new DeleteLanguage();
            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            language.Delete(command, validatorMock.Object);

            var @event = language.Events.OfType <LanguageDeleted>().SingleOrDefault();

            Assert.AreEqual(language.SiteId, @event.SiteId);
        }
Ejemplo n.º 8
0
        public void Should_add_language_deleted_event()
        {
            var language      = new Language();
            var command       = new DeleteLanguage();
            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            language.Delete(command, validatorMock.Object);

            var @event = language.Events.OfType <LanguageDeleted>().SingleOrDefault();

            Assert.IsNotNull(@event);
        }
Ejemplo n.º 9
0
        public void Delete(DeleteLanguage cmd, IValidator <DeleteLanguage> validator)
        {
            validator.ValidateCommand(cmd);

            if (Status == LanguageStatus.Deleted)
            {
                throw new Exception("Language already deleted.");
            }

            AddEvent(new LanguageDeleted
            {
                SiteId          = SiteId,
                AggregateRootId = Id
            });
        }
Ejemplo n.º 10
0
        public void Should_have_validation_error_when_site_does_not_exist()
        {
            var command = new DeleteLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();

            siteRulesMock.Setup(x => x.DoesSiteExist(command.SiteId)).Returns(false);

            var validator = new DeleteLanguageValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
Ejemplo n.º 11
0
        public void Should_throw_exception_when_deleted()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var deleteLanguageCommand = new DeleteLanguage
            {
                SiteId = language.SiteId,
                Id     = language.Id
            };
            var deleteLanguageValidatorMock = new Mock <IValidator <DeleteLanguage> >();

            deleteLanguageValidatorMock.Setup(x => x.Validate(deleteLanguageCommand)).Returns(new ValidationResult());
            language.Delete(deleteLanguageCommand, deleteLanguageValidatorMock.Object);

            Assert.Throws <Exception>(() => language.Hide(command, validatorMock.Object));
        }
Ejemplo n.º 12
0
        public void Should_throw_exception_when_language_is_not_found()
        {
            var command = new DeleteLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var repositoryMock = new Mock <ILanguageRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns((Language)null);

            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var deleteLanguageHandler = new DeleteLanguageHandler(repositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => deleteLanguageHandler.Handle(command));
        }
Ejemplo n.º 13
0
        public void Should_update_language()
        {
            var command = new DeleteLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var languageMock = new Mock <Language>();

            var repositoryMock = new Mock <ILanguageRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(languageMock.Object);

            var validatorMock = new Mock <IValidator <DeleteLanguage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var deleteLanguageHandler = new DeleteLanguageHandler(repositoryMock.Object, validatorMock.Object);

            deleteLanguageHandler.Handle(command);

            repositoryMock.Verify(x => x.Update(It.IsAny <Language>()));
        }
Ejemplo n.º 14
0
 public async Task <Unit> DeleteLanguageAsync([FromBody] DeleteLanguage deleteLanguage)
 {
     return(await _mediator.Send(deleteLanguage));
 }
Ejemplo n.º 15
0
    static Promise removeLanguage(long id)
    {
        Promise promise = new Promise();
        DeleteLanguage request = new DeleteLanguage(id);
        builder.Build(request);
        while (!request.Process().isDone) { }

        if (request.Successful()) {
            promise.Resolve();
        }
        else {
            promise.Reject(new Exception(request.GetErrorMessage()));
        }
        return promise;
    }