public DeploymentsTest() { this.registry = new Mock <RegistryManager>(); this.tenantHelper = new Mock <ITenantConnectionHelper>(); this.packageConfigClient = new Mock <IConfigClient>(); this.storageAdapterClient = new Mock <IStorageAdapterClient>(); this.tenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName); this.tenantHelper.Setup(e => e.GetRegistry()).Returns(this.registry.Object); TelemetryClient mockTelemetryClient = this.InitializeMockTelemetryChannel(); this.devices = new Mock <IDevices>(); this.storageClient = new Mock <IStorageClient>(); MockIdentity.MockClaims("one"); this.deployments = new Deployments( new AppConfig { Global = new GlobalConfig { InstrumentationKey = "instrumentationkey", }, }, new Mock <ILogger <Deployments> >().Object, new Mock <IDeploymentEventLog>().Object, this.tenantHelper.Object, this.packageConfigClient.Object, this.storageAdapterClient.Object, this.devices.Object, this.storageClient.Object, null); }
public DevicesTest() { this.registryMock = new Mock <RegistryManager>(); this.mockTenantHelper = new Mock <ITenantConnectionHelper>(); this.mockTenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName); this.mockTenantHelper.Setup(e => e.GetRegistry()).Returns(this.registryMock.Object); MockIdentity.MockClaims("one"); this.mockAsaManager = new Mock <IAsaManagerClient>(); this.mockAsaManager .Setup(x => x.BeginDeviceGroupsConversionAsync()) .ReturnsAsync(new BeginConversionApiModel()); this.mockCache = new Mock <IDeviceQueryCache>(); this.mockCache .Setup(x => x.GetCachedQueryResultAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync((DeviceServiceListModel)null); this.mockCache .Setup( x => x.SetTenantQueryResult( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DeviceQueryCacheResultServiceModel>())); this.devices = new Devices(this.mockTenantHelper.Object, this.ioTHubHostName, this.mockAsaManager.Object, this.mockCache.Object); }
public void PostNewReviewForeRestaurant_ValidInput_OkWithUrl() { //arrange var restaurantID = 10; var postedDate = new DateTime(2016, 10, 1); var createdUser = 1; int postedRating = 3; int expectedReviewNumber = 1; string postedComment = "Review comment 1"; User postingUser = new User { Id = createdUser, UserName = "******" }; var expectedResponse = new API.ViewModels.Review { Comment = postedComment, PostedDateTime = postedDate, Rating = postedRating, ReviewNumber = expectedReviewNumber, UserName = postingUser.UserName, }; var requestReview = new API.ViewModels.Review { Comment = postedComment, PostedDateTime = postedDate, Rating = postedRating, UserName = postingUser.UserName, //no review Number }; var transactionRequest = new AddReviewRequestModel { Comment = postedComment, DateTimePosted = postedDate, Rating = postedRating, RestaurantId = restaurantID, UserId = createdUser }; MockRepository.Setup(m => m.AddReviewGetNewId(transactionRequest)).Returns(expectedReviewNumber); MockRepository.Setup(m => m.DoseRestaurentIdExist(restaurantID)).Returns(true); MockRepository.Setup(m => m.DoseUserIdAlreadyExist(postingUser.Id)).Returns(true); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(createdUser); var ctrl = new ReviewsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Post(restaurantID, requestReview); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <API.ViewModels.Review>; //assert Assert.IsNotNull(createdResult, "created-201 status was not returned"); Assert.AreEqual("NewReviewForRestaurant", createdResult.RouteName); Assert.AreEqual(restaurantID, createdResult.RouteValues["id"]); //validate response ValidateReviewResponse(createdResult.Content, expectedResponse); }
public async Task LoginCheckPasswordUnauthorizedStatus() { //Arrange var userForLogin = new UserForLogin { Username = "******", Password = "******" }; var userManager = MockIdentity.GetMockUserManager(); var signInManager = MockIdentity.GetMockSignInManager(); var user = new User { Id = 1, UserName = "******" }; AuthController controller = new AuthController(userManager.Object, signInManager.Object, configMock.Object, mapperMock.Object, wrapperMock.Object); userManager.Setup(um => um.FindByNameAsync("test")) .Returns(Task.FromResult(user)).Verifiable(); signInManager.Setup(sm => sm.CheckPasswordSignInAsync(user, userForLogin.Password, It.IsAny <bool>())) .Returns(Task.FromResult(Microsoft.AspNetCore.Identity.SignInResult.Failed)).Verifiable(); //Act var action = await controller.Login(userForLogin) as UnauthorizedResult; //Assert userManager.Verify(um => um.FindByNameAsync("test"), Times.Once); signInManager.Verify(sm => sm.CheckPasswordSignInAsync(user, userForLogin.Password, It.IsAny <bool>()), Times.Once); Assert.Equal(401, action.StatusCode); }
public async Task RegisterLoginAlreadyExistsBadRequestStatus() { //Arrange var userForRegister = new UserForRegister { Username = "******", Password = "******", RepeatPassword = "******" }; var userManager = MockIdentity.GetMockUserManager(); var signInManager = MockIdentity.GetMockSignInManager(); var user = new User { UserName = "******" }; AuthController controller = new AuthController(userManager.Object, signInManager.Object, configMock.Object, mapperMock.Object, wrapperMock.Object); userManager.Setup(um => um.CreateAsync(user, "test")) .Returns(Task.FromResult(IdentityResult.Failed())); wrapperMock.Setup(u => u.UserRepository.GetLastUser()) .Returns(Task.FromResult(new User { Id = 1 })); mapperMock.Setup(m => m.Map <User>(userForRegister)).Returns(user); //Act var action = await controller.Register(userForRegister) as BadRequestObjectResult; //Assert Assert.Equal(400, action.StatusCode); Assert.NotNull(action.Value); }
public void DeleteRestaurant_ValidId_OK() { //arrange var RestIdToDelete = 155; var expectedStatusCode = HttpStatusCode.NoContent; var callingUserId = 10; var transactionRequest = new RemoveRestaurantRequestModel { RestaurantId = RestIdToDelete, UserId = callingUserId }; MockRepository.Setup(m => m.RemoveRestaurentId(transactionRequest)); MockRepository.Setup(m => m.DoseRestaurentIdExist(155)).Returns(true); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(callingUserId); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Delete(RestIdToDelete); var deletedStatusResult = actionResult as StatusCodeResult; //assert Assert.IsNotNull(deletedStatusResult, "delete-204 status was not returned"); Assert.AreEqual(expectedStatusCode, deletedStatusResult.StatusCode); }
public void GetRestaurantsOnCuisineId_NoRestaurnats_Empty() { //arrange var expectedResponse = new API.ViewModels.Restaurant[] { }; var repoResonse = new Restaurant[] { }; var cuisineId = 5; var expectedCollectionCount = 0; MockRepository.Setup(m => m.DoseCuisineIdExist(cuisineId)).Returns(true); MockRepository.Setup(m => m.GetRestaurantForCuisine(cuisineId)).Returns(repoResonse); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new CuisinesController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(cuisineId); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <API.ViewModels.Restaurant> >; //assert Assert.IsNotNull(contentResult, "Ok-200 status was not returned"); Assert.IsNotNull(contentResult.Content, "No content was returned"); RestaurantsControllerTests.ValidateRestaurantCollectionResponse(contentResult.Content, expectedResponse, expectedCollectionCount); }
public async Task RegisterOkStatus() { //Arrange var userForRegister = new UserForRegister { Username = "******", Password = "******", RepeatPassword = "******" }; var userManager = MockIdentity.GetMockUserManager(); var signInManager = MockIdentity.GetMockSignInManager(); var user = new User { UserName = "******" }; AuthController controller = new AuthController(userManager.Object, signInManager.Object, configMock.Object, mapperMock.Object, wrapperMock.Object); userManager.Setup(um => um.CreateAsync(user, "test")) .Returns(Task.FromResult(IdentityResult.Success)); wrapperMock.Setup(u => u.UserRepository.GetLastUser()).Returns(Task.FromResult(user)); mapperMock.Setup(m => m.Map <User>(userForRegister)).Returns(user); //Act var action = await controller.Register(userForRegister) as OkResult; //Assert Assert.Equal(200, action.StatusCode); }
public async Task GetUserOkStatus() { //Arrange var user = new User { Id = 1, PhotoId = 1 }; var userForReturn = new UserForReturn { PhotoId = 1 }; var userManager = MockIdentity.GetMockUserManager(); UserController controller = new UserController(wrapperMock.Object, mapperMock.Object, userManager.Object); userManager.Setup(um => um.FindByIdAsync("1")).Returns(Task.FromResult(user)); mapperMock.Setup(m => m.Map <UserForReturn>(user)).Returns(userForReturn); //Act var action = await controller.GetUser(1) as OkObjectResult; var item = action.Value as UserForReturn; //Assert Assert.Equal(200, action.StatusCode); Assert.Equal(1, item.PhotoId); }
public async Task ChefAuthorization_ShowAllowStockCreateWhenChef() { //Arrange Meal meal = new Meal { Id = 1, DayOfSesshinId = 1, Type = MealType.Breakfast }; var userManager = MockIdentity.MockUserManager <AppUser>().Object; MockMealService mockMeal = new MockMealService(); mockMeal.MockGetById(meal); mockMeal.MockGetSesshinOwner("1"); MockSesshinService mockSesshin = new MockSesshinService(); var authorizationService = MockAuthorizationService.BuildAuthorizationService(services => { services.AddScoped <IMealService>(sp => mockMeal.Object); services.AddScoped <IAuthorizationHandler>(sp => new ChefAuthorizationHandler(userManager, mockMeal.Object, mockSesshin.Object)); }); var user = new ClaimsPrincipal( new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.Name, "homer.simpson"), new Claim(ClaimTypes.Role, Constants.UserChefRole), new Claim("AccountStatus", "Approved") })); //Act var allowed = await authorizationService.AuthorizeAsync(user, new Stock(), UserOperations.Create); // Assert Assert.True(allowed.Succeeded); }
public void PatchRestaurant_ServerException_InternalError() { //arrange var updatedCuisineName = "Mexican"; var updatedCuisineId = 10; var updatedRestaurantName = "World Cafe"; var restaruantIdToUpdate = 155; var requestModel = new API.ViewModels.Restaurant { Id = restaruantIdToUpdate, CuisineName = updatedCuisineName, CuisineId = updatedCuisineId, Name = updatedRestaurantName, }; MockRepository.Setup(m => m.GetRestaurantById(restaruantIdToUpdate)); MockIdentity.Setup(m => m.GetRequestingUserId()).Throws(new Exception()); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Patch(restaruantIdToUpdate, requestModel); // assert Assert.IsInstanceOfType(actionResult, typeof(InternalServerErrorResult)); }
public void PatchRestaurant_ValidData_OK() { //arrange var originalCuisineName = "Indian"; var originalCuisineId = 1; var originalRestaurantName = "No1 Indian Restaurant"; var updatedRestaurantName = "World Cafe"; var restaruantIdToUpdate = 155; var createdUser = 10; var callingUserId = 10; var originalCuisine = new Cuisine { Name = originalCuisineName, Id = originalCuisineId, CreatedBy = createdUser, UpdatedBy = createdUser }; var restaurantBeforeUpdate = new Restaurant { Id = restaruantIdToUpdate, CreatedBy = createdUser, UpdatedBy = createdUser, Cuisine = originalCuisine, Name = originalRestaurantName }; var requestModel = new API.ViewModels.Restaurant { Id = restaruantIdToUpdate, Name = updatedRestaurantName, }; var transactionRequest = new UpdateRestaurantRequestModel { RestaurantId = restaruantIdToUpdate, Name = updatedRestaurantName, UserId = callingUserId }; MockRepository.Setup(m => m.UpdateRestaurant(transactionRequest)); MockRepository.Setup(m => m.DoseCuisineIdExist(It.IsAny <int>())).Returns(true); MockRepository.Setup(m => m.GetRestaurantById(restaruantIdToUpdate)).Returns(restaurantBeforeUpdate); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(callingUserId); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Patch(restaruantIdToUpdate, requestModel); var contentResult = actionResult as OkNegotiatedContentResult <API.ViewModels.Restaurant>; //assert Assert.IsNotNull(contentResult, "ok -200 status was not returned"); //Assert.AreEqual(HttpStatusCode..Accepted, responseRestaurants.StatusCode); //TODO: must check if se should return 201-accepted, 200-ok(with body) or 204 (ok with no content) Assert.IsNotNull(contentResult.Content); Assert.AreEqual(restaruantIdToUpdate, contentResult.Content.Id); }
public void SerializeTest() { var identity = new MockIdentity(); identity.SetAccount(account); var serializedIdentity = identity.Serialize(); Assert.False(string.IsNullOrEmpty(serializedIdentity)); }
/// <summary> /// Criar usuário padrão para servidor. /// Será utilizado para criar dados do Identity /// </summary> private void CriarUsuarioServidor() { var usuario = MockIdentity.GetUsuario(); if (!_repositoryUsuario.ExisteUsuario(usuario.NomeUsuario)) { _repositoryUsuario.Add(usuario); } }
public void GetRestaurantsOnCuisineId_OneRestaurnat_OK() { //arrange var expectedRestID = 1234; var cuisineName = "Mexican"; var cuisineId = 10; var restName = "No1 Mexican Restaurant"; var createdUser = 10; var expectedCollectionCount = 1; var cuisine = new Cuisine { Name = cuisineName, Id = cuisineId, CreatedBy = createdUser, UpdatedBy = createdUser }; var expectedResponse = new[] { new API.ViewModels.Restaurant { Id = expectedRestID, AverageRating = 0, CuisineName = cuisineName, CuisineId = cuisineId, Name = restName, ReviewCount = 0 } }; var repoResonse = new[] { new Restaurant { Id = expectedRestID, CreatedBy = createdUser, UpdatedBy = createdUser, Cuisine = cuisine, Name = restName } }; MockRepository.Setup(m => m.DoseCuisineIdExist(cuisineId)).Returns(true); MockRepository.Setup(m => m.GetRestaurantForCuisine(cuisineId)).Returns(repoResonse); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new CuisinesController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(cuisineId); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <API.ViewModels.Restaurant> >; //assert Assert.IsNotNull(contentResult, "Ok-200 status was not returned"); Assert.IsNotNull(contentResult.Content, "No content was returned"); RestaurantsControllerTests.ValidateRestaurantCollectionResponse(contentResult.Content, expectedResponse, expectedCollectionCount); }
public DevicesTest() { this.registryMock = new Mock <RegistryManager>(); this.tenantHelper = new Mock <ITenantConnectionHelper>(); this.tenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName); this.tenantHelper.Setup(e => e.GetRegistry()).Returns(this.registryMock.Object); MockIdentity.MockClaims("one"); this.devices = new Devices(this.tenantHelper.Object, this.ioTHubHostName); }
public void GetAllReviewsForRestaurant_twoReview_OK() { //arrange var restaurantId = 1; var postedDate = new DateTime(2016, 10, 1); var createdUser = 10; int postedRating = 3; int reviewNumber = 1; string postedComment = "Review comment 1"; User postingUser = new User { Id = createdUser, UserName = "******" }; var reviewEntry = new Domain.Review { Comment = postedComment, PostedDateTime = postedDate, Rating = postedRating, ReviewNumber = reviewNumber, ReviewUser = postingUser, CreatedBy = createdUser, UpdatedBy = createdUser }; var reviewEntry2 = new Domain.Review { Comment = postedComment, PostedDateTime = postedDate.AddDays(1), Rating = postedRating + 1, ReviewNumber = reviewNumber + 1, ReviewUser = postingUser, CreatedBy = createdUser, UpdatedBy = createdUser }; var repoResonse = new[] { reviewEntry, reviewEntry2 }; var expectedResponse = new List <API.ViewModels.Review>() { new API.ViewModels.Review { Comment = postedComment, PostedDateTime = postedDate, Rating = postedRating, UserName = postingUser.UserName, ReviewNumber = reviewNumber }, new API.ViewModels.Review { Comment = postedComment, PostedDateTime = postedDate.AddDays(1), Rating = postedRating + 1, UserName = postingUser.UserName, ReviewNumber = reviewNumber + 1 } }; var expectedCuisineCount = 2; MockRepository.Setup(m => m.DoseRestaurentIdExist(restaurantId)) .Returns(true); MockRepository.Setup(m => m.GetReviewsForRestaurant(restaurantId)) .Returns(repoResonse); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); ExecuteAndValidateExpectedOkResponses(restaurantId, expectedResponse, expectedCuisineCount); }
public ListingControllerTest() { listingRepo = new Mock <IListingRepo>(); var bookRepo = new Mock <IBookRepo>(); var bookApi = new Mock <IBookApi>(); var userManager = MockIdentity.UserManagerMock(); var mapper = new Mock <IMapper>(); emailSender = new Mock <IEmailSender>(); listingsAPI = new ListingsController(listingRepo.Object, bookRepo.Object, userManager.Object, bookApi.Object, mapper.Object, emailSender.Object); }
public void GetAllRestaurants_ServerException_InternalError() { //arrange MockIdentity.Setup(m => m.GetRequestingUserId()).Throws(new Exception()); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(); // assert Assert.IsInstanceOfType(actionResult, typeof(InternalServerErrorResult)); }
public void PostNewRestaurant_ValidInput_OkWithUrl() { //arrange var cuisineName = "Mexican"; var cuisineId = 10; var restName = "No1 Mexican Restaurant"; var expectedRestId = 155; var createdUser = 1; var cuisine = new Cuisine { Name = cuisineName, Id = cuisineId, CreatedBy = createdUser, UpdatedBy = createdUser }; var expectedResponse = new API.ViewModels.Restaurant { Id = expectedRestId, AverageRating = 0, CuisineName = cuisineName, CuisineId = cuisineId, Name = restName, ReviewCount = 0 }; var transactionRequest = new AddRestaurantRequestModel { CuisineId = cuisineId, Name = restName, UserId = createdUser }; MockRepository.Setup(m => m.AddRestaurentGetNewId(transactionRequest)).Returns(expectedRestId); MockRepository.Setup(m => m.GetCuisineById(It.IsAny <int>())).Returns(cuisine); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(createdUser); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Post(new API.ViewModels.Restaurant { CuisineId = cuisineId, Name = restName }); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <API.ViewModels.Restaurant>; //assert Assert.IsNotNull(createdResult, "created-201 status was not returned"); Assert.AreEqual("DefaultRouting", createdResult.RouteName); Assert.AreEqual(expectedRestId, createdResult.RouteValues["id"]); //validate response ValidateRestaurantResponse(createdResult.Content, expectedResponse); }
public void GetAllRestaurants_DatabaseException_BadData() { //arrange MockRepository.Setup(m => m.GetAllRestaurantsWithReview()).Throws(new Exception()); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(); // assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult)); }
public void GetAllCuisines_twoCuisine_OK() { //arrange var cuisineName = "Mexican"; var cuisineId = 1; var createdUser = 10; var cuisineName2 = "Indian"; var cuisineId2 = 2; var cuisine1 = new Cuisine { Name = cuisineName, Id = cuisineId, CreatedBy = createdUser, UpdatedBy = createdUser }; var cuisine2 = new Cuisine { Name = cuisineName2, Id = cuisineId2, CreatedBy = createdUser, UpdatedBy = createdUser }; var expectedResponse = new List <API.ViewModels.Cuisine>() { new API.ViewModels.Cuisine { Id = cuisineId, Name = cuisineName }, new API.ViewModels.Cuisine { Id = cuisineId2, Name = cuisineName2 } }; var expectedCuisineCount = 2; var repoResonse = new[] { cuisine1, cuisine2 }; MockRepository.Setup(m => m.GetAllCuisines()).Returns(repoResonse); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new CuisinesController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <API.ViewModels.Cuisine> >; //assert Assert.IsNotNull(contentResult, "Ok-200 status was not returned"); Assert.IsNotNull(contentResult.Content, "No content was returned"); ValidateCuisineCollectionResponse(contentResult, expectedResponse, expectedCuisineCount); }
public void DeleteRestaurant_DatabaseException_BadData() { //arrange var RestIdToDelete = 555; MockRepository.Setup(m => m.DoseRestaurentIdExist(RestIdToDelete)).Throws(new Exception()); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Delete(RestIdToDelete); // assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult)); }
public void TestInitializer() { _unitOfWork = new MockUnitOfWork(); _applicationUserRepository = _unitOfWork.GetRepository <ApplicationUser>(); _userStore = MockIdentity.MockShroomsUserStore(_unitOfWork.DbContext); _userManager = MockIdentity.MockUserManager(_userStore, _unitOfWork.DbContext); _mapper = ModelMapper.Create(); _roomController = new RoomController(_mapper, _unitOfWork, _userManager); _roomController.ControllerContext = Substitute.For <HttpControllerContext>(); _roomController.Request = new HttpRequestMessage(); _roomController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); _roomController.Request.SetConfiguration(new HttpConfiguration()); _roomController.RequestContext.Principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "1") })); }
public void Init() { var uow = Substitute.For <IUnitOfWork2>(); _usersDbSet = uow.MockDbSet(MockUsers()); _rolesDbSet = uow.MockDbSet(MockRolesForMailing()); _wallUsersDbSet = uow.MockDbSet <WallMember>(); _wallModeratorsDbSet = uow.MockDbSet <WallModerator>(); var dbContext = Substitute.For <IDbContext>(); var userStore = Substitute.For <IUserStore <ApplicationUser> >(); _userManager = MockIdentity.MockUserManager(userStore, dbContext); _userService = new UserService(uow, _userManager); }
public void DeleteRestaurant_ServerException_InternalError() { //arrange var RestIdToDelete = 555; MockRepository.Setup(m => m.DoseRestaurentIdExist(RestIdToDelete)).Returns(true); MockIdentity.Setup(m => m.GetRequestingUserId()).Throws(new Exception()); var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(RestIdToDelete); // assert Assert.IsInstanceOfType(actionResult, typeof(InternalServerErrorResult)); }
public DevicesTest() { this.registryMock = new Mock <RegistryManager>(); this.mockTenantHelper = new Mock <ITenantConnectionHelper>(); this.mockTenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName); this.mockTenantHelper.Setup(e => e.GetRegistry()).Returns(this.registryMock.Object); MockIdentity.MockClaims("one"); this.mockAsaManager = new Mock <IAsaManagerClient>(); this.mockAsaManager .Setup(x => x.BeginDeviceGroupsConversionAsync()) .ReturnsAsync(new BeginConversionApiModel()); this.devices = new Devices(this.mockTenantHelper.Object, this.ioTHubHostName, this.mockAsaManager.Object); }
public void DesirializeTest() { var identity = new MockIdentity(); identity.SetAccount(account); var serializedIdentity = identity.Serialize(); var desirializeIdenty = MockIdentity.Deserialize<MockIdentity>(serializedIdentity); Assert.False(identity == desirializeIdenty); Assert.Equal(identity.AuthenticationType, desirializeIdenty.AuthenticationType); Assert.Equal(identity.Id, desirializeIdenty.Id); Assert.Equal(identity.AuthenticationType, desirializeIdenty.AuthenticationType); Assert.Equal(identity.Name, desirializeIdenty.Name); Assert.Equal(identity.Role, desirializeIdenty.Role); }
public void DesirializeTest() { var identity = new MockIdentity(); identity.SetAccount(account); var serializedIdentity = identity.Serialize(); var desirializeIdenty = MockIdentity.Deserialize <MockIdentity>(serializedIdentity); Assert.False(identity == desirializeIdenty); Assert.Equal(identity.AuthenticationType, desirializeIdenty.AuthenticationType); Assert.Equal(identity.Id, desirializeIdenty.Id); Assert.Equal(identity.AuthenticationType, desirializeIdenty.AuthenticationType); Assert.Equal(identity.Name, desirializeIdenty.Name); Assert.Equal(identity.Role, desirializeIdenty.Role); }
public void GetRestaurantsOnCuisineId_DatabaseException_BadData() { //arrange var cuisineId = 4; MockRepository.Setup(m => m.DoseCuisineIdExist(cuisineId)).Returns(true); MockRepository.Setup(m => m.GetRestaurantForCuisine(cuisineId)).Throws(new Exception()); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new CuisinesController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(cuisineId); // assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult)); }
public async Task ChangePhotoNotFoundStatus() { //Arrange var userManager = MockIdentity.GetMockUserManager(); UserController controller = new UserController(wrapperMock.Object, mapperMock.Object, userManager.Object); userManager.Setup(um => um.FindByIdAsync("1")).Returns(Task.FromResult((User)null)); //Act var action = await controller.ChangePhoto(1, 1) as NotFoundObjectResult; //Assert Assert.Equal(404, action.StatusCode); Assert.NotNull(action.Value); }
public RuleTest() { _identity = new MockIdentity(); _identity.SetAccount(null); }
public void IfNotSetAccountThenThrowException() { var identity = new MockIdentity(); Assert.Throws<AccountNotSetException>(() => identity.Serialize()); }