public void TestAccountDetailsNull() { //Arrange Mock <IAccountDetailsRepository> mockAccountDetailsRepository = new Mock <IAccountDetailsRepository>(); mockAccountDetailsRepository.Setup(service => service.GetAccountDetails()); IAccountDetailsApplicationService accountDetailsApplicationService = new AccountDetailsApplicationService(mockAccountDetailsRepository.Object); //Act & Assert Assert.Throws <NullReferenceException>(() => accountDetailsApplicationService.GetAccountDetails()); }
/// <summary> /// Setup dependancies for controller, application service, repository. /// </summary> public AccountDetailsTest() { DbContextOptions <BookShopDatabaseontext> options = new DbContextOptionsBuilder <BookShopDatabaseontext>() .UseInMemoryDatabase(databaseName: "TestDB") .Options; BookShopDatabaseontext dbContext = new BookShopDatabaseontext(options); AccountDetailsRepository accountDetailsRepository = new AccountDetailsRepository(dbContext); AccountDetailsApplicationService accountDetailsApplicationService = new AccountDetailsApplicationService(accountDetailsRepository); accountDetailsController = new AccountDetailsController(accountDetailsApplicationService); }
public void TestAccountDetails() { //Arrange Mock <IAccountDetailsRepository> mockAccountDetailsRepository = new Mock <IAccountDetailsRepository>(); mockAccountDetailsRepository.Setup(service => service.GetAccountDetails()) .Returns(new List <AccountDetails>() { new AccountDetails(), new AccountDetails() }); IAccountDetailsApplicationService accountDetailsApplicationService = new AccountDetailsApplicationService(mockAccountDetailsRepository.Object); //Act IList <AccountDetailsDto> result = accountDetailsApplicationService.GetAccountDetails(); //Assert Assert.IsAssignableFrom <IList <AccountDetailsDto> >(result); }