示例#1
0
        public void UnknownApplication()
        {
            var controller = new AuthorizeController(null, _testConfig);
            var result     = controller.Index("unknown", null);

            Assert.IsTrue(result is HttpNotFoundResult);
        }
示例#2
0
        public async Task Authorize_No_State()
        {
            var authenticationServiceMock = new Mock <IAuthenticationService>();
            var botDataFactoryMock        = new Mock <IBotDataFactory>();
            var vstsServiceMock           = new Mock <IVstsService>();

            var target = new AuthorizeController("appId", new Uri("http://authorize.url"), authenticationServiceMock.Object, botDataFactoryMock.Object, vstsServiceMock.Object);
            var result = await target.Index("123567890", null, null) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ViewData.ModelState.First(pair => pair.Value.Errors.Any()));
        }
示例#3
0
        public async Task Authorize_No_State()
        {
            var applicationRegistry = new Mock <IVstsApplicationRegistry>();
            var botService          = new Mock <IBotService>();
            var vstsService         = new Mock <IVstsService>();

            var target = new AuthorizeController(botService.Object, applicationRegistry.Object, vstsService.Object);
            var result = await target.Index("123567890", null, null) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ViewData.ModelState.First(pair => pair.Value.Errors.Any()));
        }
        public async Task Authorize_No_Code()
        {
            var authenticationService = new Mock <IAuthenticationService>();
            var botService            = new Mock <IBotService>();
            var vstsService           = new Mock <IVstsService>();

            var target = new AuthorizeController(botService.Object, authenticationService.Object, vstsService.Object);
            var result = await target.Index(null, null, null) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ViewData.ModelState.First(pair => pair.Value.Errors.Any()));
        }
        public async Task Authorize_A_Valid_LogOn()
        {
            var authenticationService = new Mock <IAuthenticationService>();
            var botService            = new Mock <IBotService>();
            var vstsService           = new Mock <IVstsService>();

            var token    = new OAuthToken();
            var profile  = new Profile();
            var accounts = new List <Account> {
                new Account(Guid.NewGuid())
                {
                    AccountName = "Account1"
                }
            };
            var botData = new BotData();

            var target = new AuthorizeController(
                botService.Object,
                authenticationService.Object,
                vstsService.Object);

            const string code  = "1234567890";
            const string pin   = "12345";
            const string state = "channel1;user1";

            botData.SetProperty("Pin", pin);

            authenticationService
            .Setup(a => a.GetToken(code))
            .ReturnsAsync(() => token);
            vstsService
            .Setup(p => p.GetProfile(token))
            .ReturnsAsync(profile);
            vstsService
            .Setup(p => p.GetAccounts(token, It.IsAny <Guid>()))
            .ReturnsAsync(accounts);
            botService
            .Setup(b => b.GetUserData("channel1", "user1"))
            .ReturnsAsync(botData);
            botService
            .Setup(b => b.SetUserData("channel1", "user1", botData))
            .Returns(Task.CompletedTask);

            var result = await target.Index(code, string.Empty, state) as ViewResult;

            var vstsProfile = botData.GetProperty <VstsProfile>("NotValidatedByPinProfile");

            result.Should().NotBeNull();
            vstsProfile.Should().NotBeNull();
            ((Authorize)result.Model).Pin.Should().Be(pin);
        }
示例#6
0
        public async Task Authorize_A_Valid_LogOn()
        {
            var authenticationServiceMock = new Mock <IAuthenticationService>();
            var botDataFactoryMock        = new Mock <IBotDataFactory>();
            var botData         = new Mock <IBotData>();
            var botDataBag      = new Mock <IBotDataBag>();
            var vstsServiceMock = new Mock <IVstsService>();

            var token   = new OAuthToken();
            var profile = new Microsoft.VisualStudio.Services.Profile.Profile {
                DisplayName = "UniqueName"
            };
            var accounts = new List <Account> {
                new Account(Guid.NewGuid())
                {
                    AccountName = "Account1"
                }
            };

            var target = new AuthorizeController("appId", new Uri("http://authorize.url"), authenticationServiceMock.Object, botDataFactoryMock.Object, vstsServiceMock.Object);

            const string code  = "1234567890";
            const string state = "channel1;user1";
            var          data  = new UserData {
                Pin = "12345"
            };

            authenticationServiceMock
            .Setup(a => a.GetToken("appId", new Uri("http://authorize.url"), code))
            .ReturnsAsync(() => token);

            vstsServiceMock
            .Setup(p => p.GetProfile(token))
            .ReturnsAsync(profile);

            vstsServiceMock
            .Setup(p => p.GetAccounts(token, It.IsAny <Guid>()))
            .ReturnsAsync(accounts);

            botDataFactoryMock
            .Setup(b => b.Create(It.Is <Address>(a =>
                                                 a.ChannelId.Equals("channel1", StringComparison.Ordinal) &&
                                                 a.UserId.Equals("user1", StringComparison.Ordinal))))
            .Returns(botData.Object);

            botData
            .Setup(bd => bd.UserData)
            .Returns(botDataBag.Object);

            botDataBag
            .Setup(bd => bd.TryGetValue("userData", out data))
            .Returns(true);

            var result = await target.Index(code, string.Empty, state) as ViewResult;

            botDataBag
            .Verify(bd => bd.SetValue("userData", data));

            result.Should().NotBeNull();
            ((Authorize)result.Model).Pin.Should().Be(data.Pin);
            data.Profiles.Should().Contain(p => p.Id.Equals(profile.Id));
        }