public void SpremiClana_GoodModel() { AdministracijaDodajClanaVM model = new AdministracijaDodajClanaVM { Ime = "Ime", Prezime = "Prezime", TipClanarineID = 2, DatumDodavanja = new DateTime(2019, 2, 2), DatumIsteka = new DateTime(2019, 3, 3) }; Korisnik clan = null; _repository.Setup(r => r.DodajClana(It.IsAny <Korisnik>())).Callback <Korisnik>(x => clan = x); Clanarina clanarina = null; _repository.Setup(r => r.DodajClanarinu(It.IsAny <Clanarina>())).Callback <Clanarina>(x => clanarina = x); var result = _controller.SpremiClan(model) as RedirectToActionResult; _repository.Verify(x => x.DodajClana(It.IsAny <Korisnik>()), Times.Once); _repository.Verify(x => x.DodajClanarinu(It.IsAny <Clanarina>()), Times.Once); Assert.Equal(model.Ime, clan.Ime); Assert.Equal(model.Prezime, clan.Prezime); Assert.Equal(model.TipClanarineID, clanarina.TipClanarineID); Assert.Equal(model.DatumDodavanja, clanarina.DatumDodavanja); Assert.Equal(model.DatumIsteka, clanarina.DatumIsteka); Assert.Equal("AddClanPhoto", result.ActionName); }
public void SpremiClana_BadModel() { AdministracijaDodajClanaVM model = new AdministracijaDodajClanaVM { Ime = "Ime", Prezime = "Prezime", TipClanarineID = 2, DatumDodavanja = new DateTime(2019, 2, 2), DatumIsteka = new DateTime(2019, 3, 3) }; _controller.ModelState.AddModelError("BrojKartice", "BrojKartice is required"); var result = _controller.SpremiClan(model) as ViewResult; _repository.Verify(x => x.DodajClana(It.IsAny <Korisnik>()), Times.Never); _repository.Verify(x => x.DodajClanarinu(It.IsAny <Clanarina>()), Times.Never); var returnedModel = result.Model as AdministracijaDodajClanaVM; Assert.Equal(model.Ime, returnedModel.Ime); Assert.Equal(model.Prezime, returnedModel.Prezime); Assert.Equal(model.TipClanarineID, returnedModel.TipClanarineID); Assert.Equal(model.DatumDodavanja, returnedModel.DatumDodavanja); Assert.Equal(model.DatumIsteka, returnedModel.DatumIsteka); Assert.Equal("DodajClanaForma", result.ViewName); }
public IActionResult DodajClana() { AdministracijaDodajClanaVM model = new AdministracijaDodajClanaVM { spol = helper.GenereateSpolList(), DatumRodenja = DateTime.Today, clanarine = clanService.GetTipoviClanarineSelectList(), DatumDodavanja = DateTime.Now.Date }; return(View("DodajClanaForma", model)); }
public IActionResult SpremiClan(AdministracijaDodajClanaVM data) { if (!ModelState.IsValid) { data.spol = helper.GenereateSpolList(); data.clanarine = clanService.GetTipoviClanarineSelectList(); return(View("DodajClanaForma", data)); } Random rnd = new Random(); string tempUsername = data.Ime.ToLower() + "." + data.Prezime.ToLower(); KorisnickiNalog kn = new KorisnickiNalog { KorisnickoIme = clanService.IsUsernameUnique(tempUsername) == true ? tempUsername : tempUsername + rnd.Next(1, 99).ToString(), Tip = "clan", Lozinka = Guid.NewGuid().ToString() }; clanService.DodajKorisnickiNalog(kn); Korisnik clan = new Korisnik { Ime = data.Ime, Prezime = data.Prezime, BrojKartice = data.BrojKartice, BrojTelefona = data.BrojTelefona, DatumRodenja = data.DatumRodenja, Email = data.Email, Slika = "default.jpg", Spol = data.Spol, KorisnickiNalogID = kn.ID }; clanService.DodajClana(clan); HttpContext.Session.SetInt32("photoAddID", clan.ID); Clanarina clanarina = new Clanarina { ClanID = clan.ID, DatumDodavanja = data.DatumDodavanja, DatumIsteka = data.DatumIsteka, TipClanarineID = data.TipClanarineID }; clanService.DodajClanarinu(clanarina); return(RedirectToAction("ForgotPassword", "Autentifikacija", new { EmailID = clan.Email, newUserType = "clan" })); }