Пример #1
0
        public ActionResult <Club> Create(Club club
                                          )
        {
            _clubService.Create(club);

            return(CreatedAtRoute("GetClub", new { id = club.Id.ToString() }, club));
        }
Пример #2
0
        public ActionResult Create(CreateClubsViewModel createClubViewModel)
        {
            if (ModelState.IsValid)
            {
                AddressContact addressContact = CreateAddressContact(createClubViewModel);

                Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.Clubs.PocoClub, Club>());
                Club Clubs = Mapper.Map <Club>(createClubViewModel.Club);
                Clubs.AddressContactId = addressContact.Id;

                using (var context = new ClubContext())
                {
                    var service = new ClubService(context);
                    service.Create(Clubs);
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Пример #3
0
        public void Insert_Club_To_DataBase_Successesfuly_Test()
        {
            var clubData = new List <Club>().AsQueryable();

            var newClub = new Club()
            {
                Id = 1,
                AddressContactId = 1,
                Name             = "Seglarna",
                RegistrationDate = DateTime.Parse("1993-03-03"),
                Email            = "*****@*****.**",
                Logo             = "http//hejsan",
                HomePage         = "ollesSeglare.se"
            };

            //Arrange
            var fakeDbSet = A.Fake <DbSet <Club> >(o => o.Implements(typeof(IQueryable <Club>)).Implements(typeof(IDbAsyncEnumerable <Club>)));

            A.CallTo(() => ((IQueryable <Club>)fakeDbSet).Provider).Returns(clubData.Provider);
            A.CallTo(() => ((IQueryable <Club>)fakeDbSet).Expression).Returns(clubData.Expression);
            A.CallTo(() => ((IQueryable <Club>)fakeDbSet).ElementType).Returns(clubData.ElementType);
            A.CallTo(() => ((IQueryable <Club>)fakeDbSet).GetEnumerator()).Returns(clubData.GetEnumerator());

            var fakeContext = A.Fake <ClubContext>();

            A.CallTo(() => fakeContext.Clubs).Returns(fakeDbSet);
            A.CallTo(() => fakeContext.Clubs.Add(newClub)).Returns(newClub);

            var clubService = new ClubService(fakeContext);

            //Act
            var club = clubService.Create(newClub);

            //Assert
            A.CallTo(() => fakeContext.SaveChanges()).MustNotHaveHappened();
            Assert.AreEqual("Seglarna", club.Name);
            Assert.AreEqual(1, club.Id);
            Assert.AreEqual(DateTime.Parse("1993-03-03"), club.RegistrationDate, "RegistrationDate should be 1993-03-03");
        }