public void ExecuteShould_ReturnCountryNameAlreadyExistsWhenCountryFoundInDB()
        {
            var countryName = "Mordor";
            var country     = new CountryMock()
            {
                Id = 1, Name = countryName
            };

            var providerMock = new Mock <ISqlServerDataProvider>();

            providerMock.Setup(p => p.Countries.Find(It.IsAny <Expression <Func <Country, bool> > >())).Returns(new List <CountryMock>()
            {
                country
            });

            var writerMock = new Mock <IWriter>();

            var command = new AddCountryCommand(providerMock.Object, writerMock.Object);

            string result = command.Execute(new List <string>()
            {
                countryName
            });

            Assert.That(result.Contains($"Country {countryName} already exists"));
        }
Beispiel #2
0
        public MovieListViewModel(IService service)
        {
            Service = service;

            MovieFilter   = new MovieFilter();
            SelectedMovie = null;
            NewMovie      = null;
            NewActor      = null;
            NewDirector   = null;

            MovieFilterCommand              = new FilterCommand(this);
            NewMovieCommand                 = new NewItemCommand(this);
            CancelNewMovieCommand           = new CancelNewItemCommand(this);
            SaveMovieCommand                = new SaveMovieCommand(this);
            DownloadPosterFromWebApiCommand = new DownloadPosterFromWebApiCommand(this);

            AddGenreCommand    = new AddGenreCommand(this);
            AddCountryCommand  = new AddCountryCommand(this);
            AddDirectorCommand = new AddDirectorCommand(this);
            AddActorCommand    = new AddActorCommand(this);

            NewDirectorCommand       = new NewDirectorCommand(this);
            NewActorCommand          = new NewActorCommand(this);
            CancelNewActorCommand    = new CancelNewActorCommand(this);
            CancelNewDirectorCommand = new CancelNewDirectorCommand(this);
            SaveActorCommand         = new SaveActorCommand(this);
            SaveDirectorCommand      = new SaveDirectorCommand(this);

            RemoveMovieCommand = new RemoveMovieCommand(this);

            Genres    = new ObservableCollection <Genre>();
            Countries = new ObservableCollection <Country>();
            Directors = new ObservableCollection <Director>();
            Actors    = new ObservableCollection <Actor>();
        }
        public void ConstructorShould_ReturnInstanceOfAddCountryCommandClass_WhenThePassedValuesAreValid()
        {
            var providerMock = new Mock <ISqlServerDataProvider>();
            var writerMock   = new Mock <IWriter>();
            var command      = new AddCountryCommand(providerMock.Object, writerMock.Object);

            Assert.IsInstanceOf <AddCountryCommand>(command);
        }
        public void ExecuteShould_ReturnNotEnoughParametersWhenNoParametersProvided()
        {
            var providerMock = new Mock <ISqlServerDataProvider>();
            var writerMock   = new Mock <IWriter>();
            var command      = new AddCountryCommand(providerMock.Object, writerMock.Object);

            string result = command.Execute(new List <string>());

            Assert.That(result.Contains("Not enough parameters!"));
        }
        public void ExecuteShould_ClearTheScreenOneTIme()
        {
            var providerMock = new Mock <ISqlServerDataProvider>();
            var writerMock   = new Mock <IWriter>();
            var command      = new AddCountryCommand(providerMock.Object, writerMock.Object);

            command.Execute(new List <string>());

            writerMock.Verify(x => x.Clear(), Times.Once);
        }
Beispiel #6
0
        public async Task <IActionResult> AddCountry(AddCountryCommand command)
        {
            var result = await _mediator.Send(command);

            if (result == null)
            {
                return(BadRequest("User cannot have more than 10 countries or add a duplicate country code"));
            }
            return(CreatedAtRoute(nameof(GetCountryById), new { Id = result.id }, result));
        }
        public async Task <ActionResult <Result> > AddCountry([FromBody] AddCountryCommand command)
        {
            var result = await Mediator.Send(command);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Beispiel #8
0
        public async Task <ActionResult <Country> > CreateCountry(AddCountryCommand addCountryCommand)
        {
            try
            {
                Country country = await this.mediator.Send(addCountryCommand);

                return(this.Ok(country));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public void ExecuteShould_ReturnCountrySuccessMessageWhenAddedToDB()
        {
            var providerMock = new Mock <ISqlServerDataProvider>();

            providerMock.Setup(p => p.Countries.Find(It.IsAny <Expression <Func <Country, bool> > >())).Returns(new List <CountryMock>());
            providerMock.Setup(p => p.Countries.Add(It.IsAny <Country>())).Verifiable();
            providerMock.Setup(p => p.UnitOfWork.Finished()).Verifiable();

            var writerMock = new Mock <IWriter>();

            var command = new AddCountryCommand(providerMock.Object, writerMock.Object);

            string result = command.Execute(new List <string>()
            {
                "Mordor"
            });

            Assert.That(result.Contains("Country Mordor was successfully added"));
        }
        public async void Country_must_be_inserted()
        {
            await _context.Regions.AddAsync(new Regions(1, "Region Test"));

            await _context.SaveChangesAsync(CancellationToken.None);

            var countryId   = "1";
            var countryName = "Country Test";
            var regionId    = 1;

            var command = new AddCountryCommand(countryId, countryName, regionId);
            var handler = new AddCountryCommandHandler(_bus, _domainNotificationHandler, _countryRepository, _countryQuery, _regionQuery);
            var result  = await handler.Handle(command, CancellationToken.None);

            Assert.NotNull(result);

            var country = await _countryQuery.Get(countryId, CancellationToken.None);

            Assert.NotNull(country);
            Assert.Equal(countryId, country.CountryId);
            Assert.Equal(countryName, country.CountryName);
            Assert.Equal(regionId, country.Region?.RegionId);
        }