public async Task UpdateProfileAsync_ShouldBeOkObjectResult() { // Arrange var user = new User { Profile = new UserProfile("FirstName", "LastName", Gender.Male) }; TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable(); TestMock.UserService.Setup(userManager => userManager.UpdateProfileAsync(It.IsAny <User>(), It.IsAny <string>())) .ReturnsAsync(DomainValidationResult <UserProfile> .Succeeded(user.Profile)) .Verifiable(); var controller = new ProfileController(TestMock.UserService.Object, TestMapper); // Act var result = await controller.UpdateProfileAsync( new UpdateProfileRequest { FirstName = "Bob" }); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); TestMock.UserService.Verify(userManager => userManager.UpdateProfileAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Once); }
public async Task LinkCredentialAsync_ShouldBeOfTypeOkObjectResult() { // Arrange var userId = new UserId(); var credential = new Credential( userId, Game.LeagueOfLegends, new PlayerId(), new UtcNowDateTimeProvider()); TestMock.GameCredentialService.Setup(credentialService => credentialService.LinkCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(DomainValidationResult <Credential> .Succeeded(credential)) .Verifiable(); var authFactorController = new GameAuthenticationsController( TestMock.GameAuthenticationService.Object, TestMock.GameCredentialService.Object, TestMapper) { ControllerContext = { HttpContext = new MockHttpContextAccessor().Object.HttpContext } }; // Act var result = await authFactorController.LinkCredentialAsync(Game.LeagueOfLegends); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.GameCredentialService.Verify(credentialService => credentialService.LinkCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); }
public async Task CancelPromotionAsync_ShouldBeOkObjectResult() { // Arrange var promotion = GeneratePromotion(); TestMock.PromotionService .Setup( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>())) .ReturnsAsync(promotion) .Verifiable(); TestMock.PromotionService .Setup( promotionService => promotionService.CancelPromotionAsync( It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>())) .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(promotion)) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await controller.CancelPromotionAsync(TestCode); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(promotion)); TestMock.PromotionService.Verify( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>()), Times.Once); TestMock.PromotionService.Verify( promotionService => promotionService.CancelPromotionAsync( It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()), Times.Once); }
public async Task ShouldBeHttpStatusCodeOk() { // Arrange var userId = new UserId(); var factory = TestHost.WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, userId.ToString()), new Claim(CustomClaimTypes.StripeCustomer, "customerId")) .WithWebHostBuilder( builder => builder.ConfigureTestContainer <ContainerBuilder>( container => { TestMock.StripePaymentMethodService .Setup( paymentMethodService => paymentMethodService.AttachPaymentMethodAsync( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())) .ReturnsAsync( DomainValidationResult <PaymentMethod> .Succeeded( new PaymentMethod { Id = "PaymentMethodId", Type = "card", Card = new PaymentMethodCard { Brand = "Brand", Country = "CA", Last4 = "1234", ExpMonth = 11, ExpYear = 22 } })); container.RegisterInstance(TestMock.StripePaymentMethodService.Object).As <IStripePaymentMethodService>().SingleInstance(); })); _httpClient = factory.CreateClient(); // Act using var response = await this.ExecuteAsync("paymentMethodId", new AttachStripePaymentMethodRequest ()); // Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task AttachPaymentMethodAsync_ShouldBeOfTypeOkObjectResult() { // Arrange TestMock.StripePaymentMethodService .Setup(paymentMethodService => paymentMethodService.AttachPaymentMethodAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())) .ReturnsAsync( DomainValidationResult <PaymentMethod> .Succeeded( new PaymentMethod { Id = "PaymentMethodId", Type = "card", Card = new PaymentMethodCard { Brand = "Brand", Country = "CA", Last4 = "1234", ExpMonth = 11, ExpYear = 22 } })) .Verifiable(); var paymentMethodAttachController = new PaymentMethodsController( TestMock.StripePaymentMethodService.Object, TestMock.StripeCustomerService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await paymentMethodAttachController.AttachPaymentMethodAsync("paymentMethodId", new AttachStripePaymentMethodRequest()); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.StripePaymentMethodService.Verify( paymentMethodService => paymentMethodService.AttachPaymentMethodAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Once); }
public async Task CreatePromotionAsync_ShouldBeOkObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>())) .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(GeneratePromotion())) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = 50, Type = EnumCurrencyType.Money }, Duration = new Duration(), ExpiredAt = DateTime.UtcNow.ToTimestamp(), PromotionalCode = TestCode }; // Act var result = await controller.CreatePromotionAsync(request); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(GeneratePromotion())); TestMock.PromotionService.Verify( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>()), Times.Once); }
public async Task RemoveAddressAsync_ShouldBeOkObjectResult() { // Arrange var user = new User { Id = Guid.NewGuid() }; var address = new Address( UserId.FromGuid(user.Id), Country.Canada, "Line1", null, "City", "State", "PostalCode"); TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable(); TestMock.AddressService.Setup(addressService => addressService.FindUserAddressAsync(It.IsAny <User>(), It.IsAny <AddressId>())) .ReturnsAsync(address) .Verifiable(); TestMock.AddressService.Setup(addressService => addressService.RemoveAddressAsync(It.IsAny <Address>())) .ReturnsAsync(DomainValidationResult <Address> .Succeeded(address)) .Verifiable(); var controller = new AddressBookController(TestMock.UserService.Object, TestMock.AddressService.Object, TestMapper); // Act var result = await controller.RemoveAddressAsync(address.Id); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); TestMock.AddressService.Verify(addressService => addressService.FindUserAddressAsync(It.IsAny <User>(), It.IsAny <AddressId>()), Times.Once); TestMock.AddressService.Verify(addressService => addressService.RemoveAddressAsync(It.IsAny <Address>()), Times.Once); }
public async Task GenerateAuthenticationAsync_ShouldBeOfTypeOkObjectResult() { // Arrange var gameAuthentication = new LeagueOfLegendsGameAuthentication( PlayerId.Parse("playerId"), new LeagueOfLegendsGameAuthenticationFactor( 1, string.Empty, 2, string.Empty)); TestMock.GameAuthenticationService .Setup(authFactorService => authFactorService.GenerateAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <object>())) .ReturnsAsync(DomainValidationResult <GameAuthentication> .Succeeded(gameAuthentication)) .Verifiable(); var authFactorController = new GameAuthenticationsController( TestMock.GameAuthenticationService.Object, TestMock.GameCredentialService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await authFactorController.GenerateAuthenticationAsync(Game.LeagueOfLegends, "playerId"); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.GameAuthenticationService.Verify( authFactorService => authFactorService.GenerateAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <object>()), Times.Once); }
public async Task ChangeDoxatagAsync_ShouldBeOkObjectResult() { // Arrange var user = new User { Id = Guid.NewGuid() }; var doxatag = new Doxatag( UserId.FromGuid(user.Id), "Name", 1000, new UtcNowDateTimeProvider()); TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable(); TestMock.DoxatagService.Setup(doxatagService => doxatagService.ChangeDoxatagAsync(It.IsAny <User>(), It.IsAny <string>())) .ReturnsAsync(DomainValidationResult <Doxatag> .Succeeded(doxatag)) .Verifiable(); var controller = new DoxatagHistoryController(TestMock.UserService.Object, TestMock.DoxatagService.Object, TestMapper); var request = new ChangeDoxatagRequest { Name = doxatag.Name }; // Act var result = await controller.ChangeDoxatagAsync(request); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); TestMock.DoxatagService.Verify(doxatagService => doxatagService.ChangeDoxatagAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Once); }
public async Task AddAddressAsync_ShouldBeOkObjectResult() { // Arrange var user = new User { Id = Guid.NewGuid() }; var address = new Address( UserId.FromGuid(user.Id), Country.Canada, "Line1", null, "City", "State", "PostalCode"); TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable(); TestMock.AddressService.Setup( addressService => addressService.AddAddressAsync( It.IsAny <UserId>(), It.IsAny <Country>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(DomainValidationResult <Address> .Succeeded(address)) .Verifiable(); var controller = new AddressBookController(TestMock.UserService.Object, TestMock.AddressService.Object, TestMapper); var request = new CreateAddressRequest { CountryIsoCode = EnumCountryIsoCode.CA, Line1 = "1234 Test Street", Line2 = null, City = "Toronto", State = "Ontario", PostalCode = "A1A1A1" }; // Act var result = await controller.AddAddressAsync(request); // Assert result.Should().BeOfType <OkObjectResult>(); TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); TestMock.AddressService.Verify( addressService => addressService.AddAddressAsync( It.IsAny <UserId>(), It.IsAny <Country>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }