Beispiel #1
0
        public async Task HandleShouldReturnOneBetIfMemberHasCreatedOneBetInProgress()
        {
            //arrange
            var memberId = Guid.NewGuid();
            var creator  = new MemberOutput
            {
                Id       = memberId,
                Username = "******"
            };
            IQueryBetRepository betRepository = new InMemoryQueryBetRepository(creator, new List <BetOutput>()
            {
                new BetOutput
                {
                    Creator     = creator,
                    Description = "desc1",
                    Coins       = 30,
                    EndDate     = new DateTime(2022, 2, 2),
                    Id          = Guid.NewGuid()
                }
            });
            var handler = new GetBetsInProgressQueryHandler(betRepository);
            var query   = new GetBetsInProgressQuery(memberId);

            //act
            IReadOnlyCollection <BetOutput> bets = await handler.Handle(query);

            //assert
            Assert.Single(bets);
            var bet = bets.First();

            Assert.Equal(memberId, bet.Creator.Id);
        }
        public static void RegisterInMemoryDependencies()
        {
            var queryBetRepository = new InMemoryQueryBetRepository(new MemberOutput
            {
                Id       = App.CurrentUser,
                Username = App.CurrentUsername
            },
                                                                    new List <BetOutput>()
            {
                new BetOutput
                {
                    Creator = new MemberOutput
                    {
                        Id       = App.CurrentUser,
                        Username = App.CurrentUsername
                    },
                    Description  = "Description bet 1",
                    Coins        = 30,
                    EndDate      = new DateTime(2022, 2, 2),
                    Id           = Guid.NewGuid(),
                    Participants = new List <MemberOutput>
                    {
                        new MemberOutput
                        {
                            Id       = Guid.NewGuid(),
                            Username = "******"
                        }
                    }
                },
                new BetOutput
                {
                    Creator = new MemberOutput
                    {
                        Id       = App.CurrentUser,
                        Username = App.CurrentUsername
                    },
                    Description  = "Description bet 2",
                    Coins        = 30,
                    EndDate      = new DateTime(2022, 2, 2),
                    Id           = Guid.NewGuid(),
                    Participants = new List <MemberOutput>
                    {
                        new MemberOutput
                        {
                            Id       = Guid.NewGuid(),
                            Username = "******"
                        },
                        new MemberOutput
                        {
                            Id       = Guid.NewGuid(),
                            Username = "******"
                        }
                    }
                }
            });

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IQueryBetRepository>(x => queryBetRepository);
            serviceCollection.AddScoped <IBetRepository>(x => new InMemoryBetRepository(queryBetRepository));
            serviceCollection.AddScoped <IUserRepository>(x => new InMemoryUserRepository("token"));
            serviceCollection.AddScoped <IMessenger, Messenger>();
            serviceCollection.AddScoped <INavigationService, ShellNavigationService>();
            serviceCollection.AddScoped <IRetrieveBetQueryHandler, RetrieveBetQueryHandler>();
            serviceCollection.AddScoped <ILaunchBetCommandHandler, LaunchBetCommandHandler>();
            serviceCollection.AddScoped <IGetBetsInProgressQueryHandler, GetBetsInProgressQueryHandler>();
            serviceCollection.AddScoped <IRegisterCommandHandler, RegisterCommandHandler>();
            serviceCollection.AddScoped <ISignInCommandHandler, SignInCommandHandler>();
            serviceCollection.AddScoped <RegisterPresenter>();
            serviceCollection.AddScoped <SignInPresenter>();
            serviceCollection.AddScoped <IRegisterPresenter>(x => x.GetRequiredService <RegisterPresenter>());
            serviceCollection.AddScoped <ISignInPresenter>(x => x.GetRequiredService <SignInPresenter>());
            serviceCollection.AddScoped <IHashPassword, Sha256HashPassword>();
            serviceCollection.AddScoped <IHttpService, HttpService>();
            serviceCollection.AddScoped <IAuthenticationService, AuthenticationService>();
            serviceCollection.AddScoped <IAuthenticationGateway>(x => new InMemoryAuthenticationGateway(new Authentication("username", "passwordpassword", "token")));
            serviceCollection.AddScoped <IRestClient, RestClient>();
            serviceCollection.AddSingleton <LaunchBetViewModel>();
            serviceCollection.AddSingleton <InProgressBetsViewModel>();
            serviceCollection.AddSingleton <DetailBetViewModel>();
            serviceCollection.AddSingleton <RegisterViewModel>();
            serviceCollection.AddSingleton <SignInViewModel>();
            _serviceProvider = serviceCollection.BuildServiceProvider();
        }