public void Init() { this.phonebookRepository = new Mock <IPhonebookRepository>(); this.phonebookController = new PhonebookController(this.phonebookRepository.Object); var configuration = new HttpConfiguration(); var request = new System.Net.Http.HttpRequestMessage(); request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; this.phonebookController.Request = request; }
public void Init() { this.session = new Mock <HttpSessionStateBase>(); this.session.SetupGet(s => s["token"]).Returns(Guid.NewGuid()); this.httpContext = new Mock <HttpContextBase>(); this.httpContext.SetupGet(c => c.Session).Returns(session.Object); this.controllerContext = new ControllerContext(); this.controllerContext.HttpContext = httpContext.Object; this.phonebookService = new Mock <IPhonebookService>(); this.phonebookService.Setup(x => x.ValidateAndGet(It.IsAny <string>())).Returns(Guid.NewGuid().ToString()); this.phonebookController = new PhonebookController(phonebookService.Object); this.phonebookController.ControllerContext = this.controllerContext; }
public PhonebookControllerTest() { DbContextOptions dbOptions = new DbContextOptionsBuilder <PhonebookContext>() .UseInMemoryDatabase(databaseName: "Phonebook") .Options; PhonebookContext context = new PhonebookContext(dbOptions); PhonebookContextSeed.SeedAsync(context).Wait(); PhonebookRepository phoneboookRepository = new PhonebookRepository(context); MapperConfiguration config = new MapperConfiguration(cfg => { cfg.AddProfile <EntryProfile>(); cfg.CreateMap <AddEntryModel, EntryEntity>(); }); PhonebookComponent phonebookComponent = new PhonebookComponent(phoneboookRepository); _phonebookController = new PhonebookController(phonebookComponent); }
public void Setup() { options = new DbContextOptionsBuilder <AbsaPhonebookContext>().UseInMemoryDatabase(databaseName: "AbsaPhonebook").Options; var context = new AbsaPhonebookContext(options); context.RemoveRange(context.Phonebook); context.RemoveRange(context.PhonebookEntry); context.SaveChanges(); phonebook = PhonebookFactory.Create(); phonebook.Name = "Stellenbosch Directory"; phonebook.PhonebookEntries.Add(CreateEntry(phonebook, "Dave Worthington", "021979452")); phonebookEntry = CreateEntry(phonebook, "Bill Lumsden", "0215554334"); phonebook.PhonebookEntries.Add(phonebookEntry); repository = new PhonebookRepository(context); entryRepository = new PhonebookEntryRepository(context); repository.Add(phonebook); repository.Commit(); controller = new PhonebookController(repository, entryRepository); }
public void SetUp() { _service = new Mock <IPhonebookService>(); _controller = new PhonebookController(_service.Object); }