public void FreeToPlayPeriodControllerPostTest()
        {
            // Arrange
            DateTime now = DateTime.Now;
            Hero expectedHero = HeroTest.Create();
            DateTime expectedBegin = now;
            DateTime expectedEnd = now.AddDays(1);
            Hero actualHero = null;

            Mock<IHeroRepository> heroRepositoryMock = new Mock<IHeroRepository>();
            heroRepositoryMock
                .Setup(hr => hr.Save(It.IsAny<Hero>()))
                .Callback<Hero>(h => actualHero = h);
            Mock<ICryptographyService> cryptographyServiceMock = new Mock<ICryptographyService>();

            FreeToPlayPeriodPropertiesModel model = new FreeToPlayPeriodPropertiesModel(expectedHero, expectedBegin, expectedEnd);

            // Act
            OkNegotiatedContentResult<FreeToPlayPeriodViewModel> actual =
                new FreeToPlayPeriodController(heroRepositoryMock.Object, cryptographyServiceMock.Object)
                    .Post(model) as OkNegotiatedContentResult<FreeToPlayPeriodViewModel>;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Content);
            Assert.AreEqual(expectedHero, actualHero);
            Assert.AreEqual(expectedBegin, actual.Content.Begin);
            Assert.AreEqual(expectedEnd, actual.Content.End);
        }
        // Creates a period and associates it with the hero
        public IHttpActionResult Post(FreeToPlayPeriodPropertiesModel model)
        {
            Trace.TraceInformation($"Creating free to play period {model}");

            if (!ModelState.IsValid)
            {
                return BadRequest();
            }

            FreeToPlayPeriod freeToPlayPeriod = model.Hero.AddFreeToPlayPeriod(
                model.Begin.GetValueOrDefault(),
                model.End.GetValueOrDefault(),
                DateTime.Now);

            if (freeToPlayPeriod == null)
            {
                ModelState.AddModelError(null, "Free To Play period may be invalid or an existing period overlaps.");
                return BadRequest();
            }

            _heroRepository.Save(model.Hero);
            FreeToPlayPeriodViewModel freeToPlayPeriodViewModel = new FreeToPlayPeriodViewModel(freeToPlayPeriod, _cryptographyService);
            return Ok(freeToPlayPeriodViewModel);
        }