Esempio n. 1
0
        public async Task TestUpdateAppEntranceAsync()
        {
            var model = new AppEntrance()
            {
                Id = Guid.NewGuid()
            };

            var workbenchAppService = Substitute.For <IWorkbenchAppService>();

            workbenchAppService.AddOrUpdateEntrancesAsync(Arg.Is <AddEntrancesInput>(
                                                              o => o.ClientId == Client.DefaultId && o.AppEntrances[0] == model
                                                              ))
            .Returns(Task.FromResult(true));

            var target = new WorkbenchController(
                workbenchAppService,
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.UpdateAppEntranceAsync(model);

            result.Should().BeOfType <OkObjectResult>();
            var realResult = result.As <OkObjectResult>();

            realResult.Value.Should().Be(true);
        }
Esempio n. 2
0
        public async Task TestGetTodoCenterBizSystemsAsync()
        {
            var model = new List <TodoCenterBizSystem>
            {
                new TodoCenterBizSystem
                {
                    Id = "aaa"
                }
            };
            var todoCenterAppService = Substitute.For <IBizSystemAppService>();

            todoCenterAppService.GetAllForTodoCenterAsync()
            .Returns(Task.FromResult(model));

            var target = new WorkbenchController(
                Substitute.For <IWorkbenchAppService>(),
                Substitute.For <IClientAppService>(),
                todoCenterAppService,
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.GetTodoCenterBizSystemsAsync();

            var lst = result.Value.As <List <TodoCenterBizSystem> >();

            lst.Should().NotBeNullOrEmpty();
            lst[0].Id.Should().Be("aaa");
        }
Esempio n. 3
0
        public async Task TestGetAppEntrancesAsync()
        {
            var workbenchAppService = Substitute.For <IWorkbenchAppService>();

            workbenchAppService.GetAppEntrancesRawByClientIdAsync(Client.DefaultId)
            .Returns(Task.FromResult(new List <AppEntrance>()
            {
                new AppEntrance {
                    Id = new Guid("0459738c0233483cabb53295e3bae783")
                }
            }
                                     ));

            var target = new WorkbenchController(
                workbenchAppService,
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.GetAppEntrancesAsync();

            var lst = result.Value.As <List <AppEntrance> >();

            lst.Should().NotBeNullOrEmpty();
            lst[0].Id.Should().Be(new Guid("0459738c0233483cabb53295e3bae783"));
        }
Esempio n. 4
0
        public async Task TestAddOrUpdateTodoCenterBizSystemAsync()
        {
            var todoCenterAppService = Substitute.For <IBizSystemAppService>();

            todoCenterAppService.AddOrUpdateForTodoCenterAsync(Arg.Any <TodoCenterBizSystem>())
            .Returns(Task.FromResult(true));

            var target = new WorkbenchController(
                Substitute.For <IWorkbenchAppService>(),
                Substitute.For <IClientAppService>(),
                todoCenterAppService,
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.AddOrUpdateTodoCenterBizSystemAsync(new TodoCenterBizSystem
            {
                Id = "aaa"
            });

            result.Should().BeOfType <OkObjectResult>();
            var realResult = result.As <OkObjectResult>();

            realResult.Value.Should().Be(true);
        }
        public async Task GetAll()
        {
            var workbenchAppService = Substitute.For <IWorkbenchAppService>();

            workbenchAppService.GetAppEntrancesAsync(Arg.Is <GetAppEntrancesInput>(o =>
                                                                                   o.ClientId == Client.DefaultId && o.ClientPlatform == ClientPlatform.Android))
            .Returns(Task.FromResult(new List <AppEntranceDto>
            {
                new AppEntranceDto
                {
                    Id    = Guid.NewGuid(),
                    AppId = "aaa",
                },
                new AppEntranceDto
                {
                    Id    = Guid.NewGuid(),
                    AppId = "bbb"
                }
            }));

            var target = new WorkbenchController(
                workbenchAppService,
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.GetAll(ClientPlatform.Android);

            result.Value.Should().NotBeNull();
            result.Value.Count.Should().Be(2);
        }
        public async Task CheckAuthStatus()
        {
            var deviceCode    = Guid.NewGuid().ToString("N");
            var appEntranceId = Guid.NewGuid();

            var userSettingAppService = Substitute.For <IUserSettingAppService>();

            userSettingAppService.GetAppEntranceAuthStateAsync(User_Id, deviceCode, appEntranceId)
            .Returns(true);

            var target = new WorkbenchController(
                Substitute.For <IWorkbenchAppService>(),
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => userSettingAppService);

            target.ControllerContext = CreateMockContext();

            var result = await target.CheckAuthStatus(appEntranceId, deviceCode);

            result.Value.Should().BeTrue();
            await userSettingAppService.Received(1).GetAppEntranceAuthStateAsync(User_Id, deviceCode, appEntranceId);
        }
        public async Task SendAuthCode()
        {
            var mobileCodeSender = Substitute.For <IMobileCodeSender>();

            mobileCodeSender.SendAsync(Arg.Any <string>())
            .Returns("1234");
            var target = new WorkbenchController(
                Substitute.For <IWorkbenchAppService>(),
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                mobileCodeSender,
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.SendAuthCode();

            result.Value.Should().NotBeNull();
            result.Value.Data.Should().Contain("5678");
        }
        public async Task GetBadgeAmount()
        {
            var config = new ComponentConfig
            {
                AuthType    = ComponentDataSourceAuthType.None,
                DataSources = new List <ComponentDataSource>
                {
                    new ComponentDataSource
                    {
                        Key = ComponentDataSourceKeys.BadgeValue
                    }
                }
            };

            var workbenchAppService = Substitute.For <IWorkbenchAppService>();

            workbenchAppService.GetComponentConfigAsync(Arg.Any <Guid>())
            .Returns(Task.FromResult(config));

            var apiClient = Substitute.For <IBadgeApiClient>();

            apiClient.GetAmountAsync(config)
            .Returns(Task.FromResult <int?>(1));

            var target = new WorkbenchController(
                workbenchAppService,
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                apiClient,
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.GetBadgeAmount(Guid.NewGuid());

            result.Value.Should().Be(1);
        }
Esempio n. 9
0
        public async Task TestRemoveAppEntranceAsync()
        {
            var workbenchAppService = Substitute.For <IWorkbenchAppService>();

            workbenchAppService.RemoveEntranceAsync(Client.DefaultId, Arg.Any <Guid>())
            .Returns(Task.FromResult(true));

            var target = new WorkbenchController(
                workbenchAppService,
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                Substitute.For <IMobileCodeSender>(),
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.RemoveAppEntranceAsync(Guid.NewGuid());

            result.Should().BeOfType <OkObjectResult>();
            var realResult = result.As <OkObjectResult>();

            realResult.Value.Should().Be(true);
        }
        public async Task CheckAuthCode()
        {
            var deviceCode    = Guid.NewGuid().ToString("N");
            var appEntranceId = Guid.NewGuid();

            var mobileCodeSender = Substitute.For <IMobileCodeSender>();

            mobileCodeSender.CheckAsync(Arg.Any <string>(), "1234")
            .Returns(true);

            var userSettingAppService = Substitute.For <IUserSettingAppService>();

            userSettingAppService.SetAppEntranceAuthStateAsync(User_Id, Arg.Any <AppEntranceAuthStateInput>())
            .Returns(Task.CompletedTask);

            var target = new WorkbenchController(
                Substitute.For <IWorkbenchAppService>(),
                Substitute.For <IClientAppService>(),
                Substitute.For <IBizSystemAppService>(),
                Substitute.For <IBadgeApiClient>(),
                mobileCodeSender,
                _ => userSettingAppService);

            target.ControllerContext = CreateMockContext();

            var result = await target.CheckAuthCode(new CheckAuthCodeVm
            {
                AppEntranceId = appEntranceId,
                DeviceCode    = deviceCode,
                MobileCode    = "1234"
            });

            result.Value.Should().BeTrue();
            await userSettingAppService.Received().SetAppEntranceAuthStateAsync(User_Id,
                                                                                Arg.Is <AppEntranceAuthStateInput>(x => x.DeviceCode == deviceCode && x.AppEntranceId == appEntranceId));
        }