Exemplo n.º 1
0
        public void When_AddPerformance_is_mapped_to_a_Performance_and_the_url_is_an_empty_string_then_the_values_except_the_Uri_are_mapped_correctly()
        {
            var startDateTime = DateTime.Now.AddDays(37);

            var addPerformanceModel = new AddPerformanceModel
            {
                Date      = startDateTime.Date,
                StartTime = startDateTime,
                EndTime   = startDateTime.AddHours(4),
                City      = "City",
                VenueName = "VenueName",
                VenueUrl  = string.Empty,
                Info      = "Info",
                Price     = 15,
            };

            var result = Mapper.Map(addPerformanceModel);

            Assert.AreEqual(addPerformanceModel.Date.ToString("yyyyMMdd", CultureInfo.InvariantCulture), result.StartDateTime.ToString("yyyyMMdd", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.StartTime.ToString("HH:mm", CultureInfo.InvariantCulture), result.StartDateTime.ToString("HH:mm", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.EndTime.ToString("HH:mm", CultureInfo.InvariantCulture), result.EndDateTime.ToString("HH:mm", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.City, result.City);
            Assert.AreEqual(addPerformanceModel.VenueName, result.VenueName);
            Assert.AreEqual(addPerformanceModel.Price.ToString("{0:C}", CultureInfo.InvariantCulture), result.Price.ToString("{0:C}", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.Info, result.Info);
            Assert.AreEqual(null, result.VenueUri);
        }
Exemplo n.º 2
0
        public void When_AddPerformance_is_mapped_to_a_Performance_and_the_url_is_null_then_the_values_except_the_Uri_are_mapped_correctly()
        {
            var startDateTime = DateTime.Now.AddDays(37);

            var addPerformanceModel = new AddPerformanceModel
                                          {
                                              Date = startDateTime.Date,
                                              StartTime = startDateTime,
                                              EndTime = startDateTime.AddHours(4),
                                              City = "City",
                                              VenueName = "VenueName",
                                              VenueUrl = null,
                                              Info = "Info",
                                              Price = 15,
                                          };

            var result = Mapper.Map(addPerformanceModel);

            Assert.AreEqual(addPerformanceModel.Date.ToString("yyyyMMdd", CultureInfo.InvariantCulture), result.StartDateTime.ToString("yyyyMMdd", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.StartTime.ToString("HH:mm", CultureInfo.InvariantCulture), result.StartDateTime.ToString("HH:mm", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.EndTime.ToString("HH:mm", CultureInfo.InvariantCulture), result.EndDateTime.ToString("HH:mm", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.City, result.City);
            Assert.AreEqual(addPerformanceModel.VenueName, result.VenueName);
            Assert.AreEqual(addPerformanceModel.Price.ToString("{0:C}", CultureInfo.InvariantCulture), result.Price.ToString("{0:C}", CultureInfo.InvariantCulture));
            Assert.AreEqual(addPerformanceModel.Info, result.Info);
            Assert.AreEqual(null, result.VenueUri);
        }
Exemplo n.º 3
0
        public Performance Map(AddPerformanceModel model)
        {
            return new Performance
                       {
                           StartDateTime = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day,
                                                        model.StartTime.Hour, model.StartTime.Minute,
                                                        model.StartTime.Second, model.StartTime.Millisecond),
                           EndDateTime = new DateTime(model.EndTime.Year, model.EndTime.Month, model.EndTime.Day,
                                                      model.EndTime.Hour, model.EndTime.Minute,
                                                      model.EndTime.Second, model.EndTime.Millisecond),

                           City = model.City,
                           VenueName = model.VenueName,
                           VenueUri = GetUri(model.VenueUrl),
                           Info = model.Info,
                           Price = model.Price,
                       };
        }
Exemplo n.º 4
0
        public Performance Map(AddPerformanceModel model)
        {
            return(new Performance
            {
                StartDateTime = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day,
                                             model.StartTime.Hour, model.StartTime.Minute,
                                             model.StartTime.Second, model.StartTime.Millisecond),
                EndDateTime = new DateTime(model.EndTime.Year, model.EndTime.Month, model.EndTime.Day,
                                           model.EndTime.Hour, model.EndTime.Minute,
                                           model.EndTime.Second, model.EndTime.Millisecond),

                City = model.City,
                VenueName = model.VenueName,
                VenueUri = GetUri(model.VenueUrl),
                Info = model.Info,
                Price = model.Price,
            });
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Create(AddPerformanceModel model)
        {
            try
            {
                return(await CatalogsConsumerHelper.ExecuteWithCatalogScopeAsync(
                           container =>
                {
                    var mapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IPerformanceMapper>(container);
                    var entity = mapper.Map(model);

                    var process = CatalogsConsumerHelper.ResolveCatalogsConsumer <IPerformanceProcess>(container);
                    process.AddPerformance(entity);

                    return RedirectToAction("Index");
                }));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage);
                return(View(model));
            }
        }
Exemplo n.º 6
0
        public async Task<ActionResult> Create(AddPerformanceModel model)
        {
            try
            {
                return await CatalogsConsumerHelper.ExecuteWithCatalogScopeAsync(
                    container =>
                        {
                            var mapper = CatalogsConsumerHelper.ResolveCatalogsConsumer<IPerformanceMapper>(container);
                            var entity = mapper.Map(model);

                            var process = CatalogsConsumerHelper.ResolveCatalogsConsumer<IPerformanceProcess>(container);
                            process.AddPerformance(entity);

                            return RedirectToAction("Index");
                        });
            }
            catch (Exception)
            {
                ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage);
                return View(model);
            }
        }