Esempio n. 1
0
        public async Task FileExportFileImport_TreeWithTwoPeople_PeoplePropertiesAreImported()
        {
            var tree = await PrepareTreeWithTwoPeople();

            var export =
                await QueriesExecutor.Execute(new GetTreeFileExportQuery(AuthId, new TreeId(tree.TreeId)));

            const string createdTreeName = "Drzewko 🍑";
            var          document        = new Document(export, "text/xml", "Drzewko");
            var          importTreeId    = await CommandsExecutor.Execute(new CreateTreeFromFileCommand(AuthId, Mail, document, createdTreeName));

            var importedTree = await QueriesExecutor.Execute(new GetTreeQuery(AuthId, importTreeId));


            Assert.Equal(createdTreeName, importedTree.TreeName);

            var princeExpected = tree.People.First(p => p.Gender == Gender.Male);
            var queenExpected  = tree.People.First(p => p.Gender != Gender.Male);
            var prince         = tree.People.First(p => p.Gender == Gender.Male);
            var queen          = tree.People.First(p => p.Gender != Gender.Male);

            AssertPersonFieldsEqual(princeExpected, prince);
            AssertPersonFieldsEqual(queenExpected, queen);

            Assert.Equal(queen.Id, prince.Mother);
        }
Esempio n. 2
0
 public async Task CreateProfile_TooLongName_ThrowsException()
 {
     await Assert.ThrowsAsync <InvalidCommandException>(async() =>
                                                        await CommandsExecutor.Execute(
                                                            new CreateOrUpdateUserProfileCommand(AuthId, Mail, new string('a', StringLengths.Short + 1), LastName,
                                                                                                 BirthDate)));
 }
Esempio n. 3
0
        private async Task AddPersonsMainPhoto_HappyPath_FileIsReturnedInQuery()
        {
            _applicationFixture.FileSaver
            .UploadFile(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>())
            .Returns(_uriExample);

            var fileId = await CommandsExecutor.Execute(
                new AddOrChangePersonsPhotoCommand(AuthId, _treeId, new Document(Stream.Null, "image/jpeg", "jeden"), _queenId));

            Assert.NotNull(fileId);

            var tree = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, _treeId));

            var fileFromQueryId = tree.People.FirstOrDefault()?.MainPhoto;

            Assert.Equal(fileId.Id.Value, fileFromQueryId?.Id);
            Assert.Equal("jeden", fileFromQueryId?.Name);


            var fileId2 = await CommandsExecutor.Execute(
                new AddOrChangePersonsPhotoCommand(AuthId, _treeId, new Document(Stream.Null, "image/jpeg", "dwa"), _queenId));

            var tree2 = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, _treeId));

            var fileFromQueryId2 = tree2.People.FirstOrDefault()?.MainPhoto;

            Assert.Equal(fileId2.Id.Value, fileFromQueryId2?.Id);
            Assert.Equal("dwa", fileFromQueryId2?.Name);
        }
Esempio n. 4
0
 public void Run()
 {
     _consoleCommandProducer.ListenCommands(_cancellationTokenSource.Token);
     while (true)
     {
         try
         {
             if (_inputPipeline.TryGetMessage(out Message message))
             {
                 _context.Execute(message.Content, message.CustomizedOutput ?? _output)
                 .ConfigureAwait(false)
                 .GetAwaiter()
                 .GetResult();
                 _cancellationTokenSource.Token.ThrowIfCancellationRequested();
                 Thread.Sleep(50);
             }
         }
         catch (OperationCanceledException)
         {
             _output.Write("ill be back baby");
             return;
         }
         catch (ArgumentException)
         {
             _output.Write("command received unexpected arguments count");
         }
         catch (Exception ex)
         {
             _output.Write("error: " + ex.Message);
         }
     }
 }
        private async Task ProcessCommand(
            InternalCommandDto internalCommand)
        {
            var     type             = _internalCommandsMapper.GetType(internalCommand.Type);
            dynamic commandToProcess = JsonConvert.DeserializeObject(internalCommand.Data, type);

            await CommandsExecutor.Execute(commandToProcess);
        }
        private async Task ProcessCommand(
            InternalCommandDto internalCommand)
        {
            Type    type             = Assemblies.Application.GetType(internalCommand.Type);
            dynamic commandToProcess = JsonConvert.DeserializeObject(internalCommand.Data, type);

            await CommandsExecutor.Execute(commandToProcess);
        }
        protected async Task <TreeId> CreateTree()
        {
            await CommandsExecutor.Execute(
                new CreateOrUpdateUserProfileCommand(AuthId, Mail, Name, LastName, BirthDate));

            return(await CommandsExecutor.Execute(
                       new CreateTreeCommand(TreeName, AuthId, Mail)));
        }
        private async Task EditMatch(MatchResponse match, Guid existingMatchId)
        {
            var date  = TryParseDate(match.dateEvent, match.strTime);
            var score = Score.CreateNew("Placeholder", TryParseInt(match.intHomeScore), TryParseInt(match.intAwayScore));

            var command = new EditMatchGeneralAttributesCommand(existingMatchId, match.strEvent, date.GetValueOrDefault(),
                                                                score, match.strSeason, "Placeholder");

            await CommandsExecutor.Execute(command);
        }
Esempio n. 9
0
        private void SendRequestBtn_Click(object sender, RoutedEventArgs e)
        {
            var executor = new CommandsExecutor(Login, Token, SimulationOrChaarr);

            result = executor.Execute(command, parameter, this.value);
            if (result != null)
            {
                UpdateInfo(result);
            }
        }
Esempio n. 10
0
        private async Task ExportFile_HappyPath_FileIsExportetAndContainsProperData()
        {
            var treeId = await CreateTree();

            var queenId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Elżbieta",
                    "II",
                    Gender.Female,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));


            var princeId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Filip",
                    null,
                    Gender.Male,
                    new DateTime(1921, 5, 10),
                    null,
                    "Prince",
                    "Some biography of Filip",
                    new List <Relation>
            {
                new Relation(queenId, RelationDirection.FromAddedPerson, RelationType.Spouse)
            }));

            var tree = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, treeId));

            var stream = await QueriesExecutor.Execute(
                new GetTreeFileExportQuery(AuthId, treeId));

            var serializer = new XmlSerializer(typeof(Gx.Gedcomx));

            var gedcom = (Gx.Gedcomx)serializer.Deserialize(stream);


            Assert.NotNull(gedcom);
            Assert.Equal(2, gedcom.Persons.Count);


            Assert.Single(gedcom.Persons,
                          p => p.Names.SelectMany(name => name.NameForm.Parts).Any(np => string.Equals(np.Value, "Elżbieta")));

            Assert.NotNull(gedcom.Relationships);

            Assert.Equal(RelationshipType.Couple, gedcom.Relationships.First().KnownType);
        }
Esempio n. 11
0
        private async Task <Uri> AddExampleFile(TreeId treeId)
        {
            var file = new Document(Stream.Null, "image/png", "ASDF.png");

            _applicationFixture.FileSaver
            .UploadFile(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Stream>(),
                        Arg.Any <CancellationToken>())
            .Returns(_uriExample);

            return(await CommandsExecutor.Execute(
                       new AddOrChangeTreePhotoCommand(AuthId, treeId, file)));
        }
Esempio n. 12
0
        private static async Task ProcessCommand(InternalCommandDto internalCommand)
        {
            var type = typeof(ICustomersModule).Assembly.GetType(internalCommand.Type);

            if (null == type)
            {
                throw new ArgumentNullException(nameof(type));
            }

            dynamic commandToProcess = JsonConvert.DeserializeObject(internalCommand.Data, type);
            await CommandsExecutor.Execute(commandToProcess);
        }
        private async Task AddMatch(MatchResponse match, TeamDto homeTeam, TeamDto awayTeam)
        {
            var date = TryParseDate(match.dateEvent, match.strTime);

            var score = Score.CreateNew("Placeholder", TryParseInt(match.intHomeScore), TryParseInt(match.intAwayScore));

            var command = new CreateMatchCommand(match.strEvent, homeTeam.Id, awayTeam.Id, date.GetValueOrDefault(), "Placeholder",
                                                 score, match.strSeason,
                                                 match.idEvent);

            await CommandsExecutor.Execute(command);
        }
Esempio n. 14
0
        public async Task AddOwner_NotOwnerAdding_ThrowsUnauthorized()
        {
            var userId = await CommandsExecutor.Execute(
                new CreateOrUpdateUserProfileCommand(AuthId, Mail, Name, LastName, BirthDate));

            var treeId = await CommandsExecutor.Execute(
                new CreateTreeCommand(TreeName, AuthId, Mail));

            _applicationFixture.UserAuthIdProvider
            .GetUserAuthId(Arg.Any <MailAddress>(), Arg.Any <CancellationToken>())
            .Returns(AuthId + "2");

            await Assert.ThrowsAsync <UnauthorizedException>(async() => await CommandsExecutor.Execute(
                                                                 new AddTreeOwnerCommand(AuthId + "2", treeId, "*****@*****.**")));
        }
Esempio n. 15
0
        private async Task Init()
        {
            _treeId = await CreateTree();

            _queenId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    _treeId,
                    "Elżbieta",
                    "II",
                    Gender.Female,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));
        }
Esempio n. 16
0
        public async Task AddPersonToTree_HappyPath_PeopleAreAdded()
        {
            var treeId = await CreateTree();

            var queenId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Elżbieta",
                    "II",
                    Gender.Female,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));


            var princeId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Filip",
                    null,
                    Gender.Male,
                    new DateTime(1921, 5, 10),
                    null,
                    "Prince",
                    "Some biography of Filip",
                    new List <Relation>
            {
                new Relation(queenId, RelationDirection.FromAddedPerson, RelationType.Spouse)
            }));

            var tree = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, treeId));

            Assert.Equal(2, tree.People.Count);
            Assert.NotNull(tree.People.FirstOrDefault()?.Spouse);
            Assert.Null(tree.People.FirstOrDefault()?.Mother);
            Assert.Null(tree.People.FirstOrDefault()?.Father);

            Assert.Equal(TreeName, tree.TreeName);
            Assert.Equal(treeId.Value, tree.TreeId);
        }
Esempio n. 17
0
        private async Task RemovePersonsFile_HappyPath_FileIsDeleted()
        {
            _applicationFixture.FileSaver
            .UploadFile(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>())
            .Returns(_uriExample);

            var file = await CommandsExecutor.Execute(
                new AddPersonsFileCommand(AuthId, _treeId, new Document(Stream.Null, "image/jpeg", "file"), _queenId));

            await CommandsExecutor.Execute(
                new RemovePersonsFileCommand(AuthId, _treeId, file.Id, _queenId));

            var tree = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, _treeId));

            var files = tree.People.FirstOrDefault()?.Files;

            Assert.NotNull(files);
            Assert.Empty(files);
        }
        public async Task PlaceOrder_Test()
        {
            string      customerEmail = "*****@*****.**";
            CustomerDto customer      =
                await CommandsExecutor.Execute(new RegisterCustomerCommand(customerEmail, "Sample Customer"));

            List <ProductDto> products = new List <ProductDto>();
            Guid productId             = Guid.Parse("9DB6E474-AE74-4CF5-A0DC-BA23A42E2566");

            products.Add(new ProductDto(productId, 2));
            Guid orderId = await CommandsExecutor.Execute(new PlaceCustomerOrderCommand(customer.Id, products, "EUR"));

            OrderDetailsDto orderDetails = await QueriesExecutor.Execute(new GetCustomerOrderDetailsQuery(orderId));

            Assert.That(orderDetails, Is.Not.Null);
            Assert.That(orderDetails.Value, Is.EqualTo(70));
            Assert.That(orderDetails.Products.Count, Is.EqualTo(1));
            Assert.That(orderDetails.Products[0].Quantity, Is.EqualTo(2));
            Assert.That(orderDetails.Products[0].Id, Is.EqualTo(productId));

            SqlConnection           connection   = new SqlConnection(ConnectionString);
            List <OutboxMessageDto> messagesList = await OutboxMessagesHelper.GetOutboxMessages(connection);

            Assert.That(messagesList.Count, Is.EqualTo(3));

            CustomerRegisteredNotification customerRegisteredNotification =
                OutboxMessagesHelper.Deserialize <CustomerRegisteredNotification>(messagesList[0]);

            Assert.That(customerRegisteredNotification.CustomerId, Is.EqualTo(new CustomerId(customer.Id)));

            OrderPlacedNotification orderPlaced =
                OutboxMessagesHelper.Deserialize <OrderPlacedNotification>(messagesList[1]);

            Assert.That(orderPlaced.OrderId, Is.EqualTo(new OrderId(orderId)));

            PaymentCreatedNotification paymentCreated =
                OutboxMessagesHelper.Deserialize <PaymentCreatedNotification>(messagesList[2]);

            Assert.That(paymentCreated, Is.Not.Null);
        }
Esempio n. 19
0
        public async Task CreateProfileAndTreeAddTreeOwner_HappyPath_AddsTreeOwner()
        {
            var userId = await CommandsExecutor.Execute(
                new CreateOrUpdateUserProfileCommand(AuthId, Mail, Name, LastName, BirthDate));

            var treeId = await CommandsExecutor.Execute(
                new CreateTreeCommand(TreeName, AuthId, Mail));

            var userId2 = await CommandsExecutor.Execute(
                new CreateOrUpdateUserProfileCommand(AuthId + "2", Mail, Name + "2", LastName + "2", BirthDate));


            _applicationFixture.UserAuthIdProvider
            .GetUserAuthId(Arg.Any <MailAddress>(), Arg.Any <CancellationToken>())
            .Returns(AuthId + "2");

            await CommandsExecutor.Execute(
                new AddTreeOwnerCommand(AuthId, treeId, "*****@*****.**"));

            await CommandsExecutor.Execute(
                new RemoveTreeOwnerCommand(AuthId + "2", treeId, userId));
        }
Esempio n. 20
0
        public async Task PlaceOrder_Test()
        {
            var customerEmail = "*****@*****.**";
            var customer      = await CommandsExecutor.Execute(new RegisterCustomerCommand(customerEmail, "soheil bijavar"));

            List <ProductDto> products = new List <ProductDto>();
            var productId = Guid.Parse("cdd19ddd-647a-4af7-9f95-cfef9e346c40");

            products.Add(new ProductDto(productId, 2));
            var orderId = await CommandsExecutor.Execute(new PlaceCustomerOrderCommand(customer.Id, products, "Rial"));

            var orderDetails = await QueriesExecutor.Execute(new GetCustomerOrderDetailsQuery(orderId));

            Assert.That(orderDetails, Is.Not.Null);
            Assert.That(orderDetails.Value, Is.EqualTo(80));
            Assert.That(orderDetails.Products.Count, Is.EqualTo(1));
            Assert.That(orderDetails.Products[0].Quantity, Is.EqualTo(2));
            Assert.That(orderDetails.Products[0].Id, Is.EqualTo(productId));

            var connection   = new SqlConnection(ConnectionString);
            var messagesList = await OutboxMessagesHelper.GetOutboxMessages(connection);

            Assert.That(messagesList.Count, Is.EqualTo(3));

            var customerRegisteredNotification =
                OutboxMessagesHelper.Deserialize <CustomerRegisteredNotification>(messagesList[0]);

            Assert.That(customerRegisteredNotification.CustomerId, Is.EqualTo(new CustomerId(customer.Id)));

            var orderPlaced =
                OutboxMessagesHelper.Deserialize <OrderPlacedNotification>(messagesList[1]);

            Assert.That(orderPlaced.OrderId, Is.EqualTo(new OrderId(orderId)));

            var paymentCreated =
                OutboxMessagesHelper.Deserialize <PaymentCreatedNotification>(messagesList[2]);

            Assert.That(paymentCreated, Is.Not.Null);
        }
Esempio n. 21
0
        public async Task <Unit> Handle(ProcessInternalCommandsCommand command, CancellationToken cancellationToken)
        {
            IDbConnection connection = _sqlConnectionFactory.GetOpenConnection();

            const string sql = "SELECT " +
                               "[Command].[Type], " +
                               "[Command].[Data] " +
                               "FROM [app].[InternalCommands] AS [Command] " +
                               "WHERE [Command].[ProcessedDate] IS NULL";
            IEnumerable <InternalCommandDto> commands = await connection.QueryAsync <InternalCommandDto>(sql);

            List <InternalCommandDto> internalCommandsList = commands.AsList();

            foreach (InternalCommandDto internalCommand in internalCommandsList)
            {
                Type?   type             = Assemblies.Application.GetType(internalCommand.Type);
                dynamic commandToProcess = JsonConvert.DeserializeObject(internalCommand.Data, type);

                await CommandsExecutor.Execute(commandToProcess);
            }

            return(Unit.Value);
        }
        public async Task <Unit> Handle(ProcessInternalCommandsCommand command, CancellationToken cancellationToken)
        {
            var connection = this._sqlConnectionFactory.GetOpenConnection();

            const string sql = "SELECT " +
                               "[Command].[Type], " +
                               "[Command].[Data] " +
                               "FROM [payments].[InternalCommands] AS [Command] " +
                               "WHERE [Command].[ProcessedDate] IS NULL";
            var commands = await connection.QueryAsync <InternalCommandDto>(sql);

            var internalCommandsList = commands.AsList();

            foreach (var internalCommand in internalCommandsList)
            {
                Type type             = Assembly.GetExecutingAssembly().GetType(internalCommand.Type);
                var  commandToProcess = JsonConvert.DeserializeObject(internalCommand.Data, type) as ICommand;

                await CommandsExecutor.Execute(commandToProcess);
            }

            return(Unit.Value);
        }
Esempio n. 23
0
        public async Task RegisterCustomerTest()
        {
            const string email = "*****@*****.**";
            const string name  = "soheil bijavar company";

            var customer = await CommandsExecutor.Execute(new RegisterCustomerCommand(email, name));

            var customerDetails = await QueriesExecutor.Execute(new GetCustomerDetailsQuery(customer.Id));

            Assert.That(customerDetails, Is.Not.Null);
            Assert.That(customerDetails.Name, Is.EqualTo(name));
            Assert.That(customerDetails.Email, Is.EqualTo(email));

            var connection   = new SqlConnection(ConnectionString);
            var messagesList = await OutboxMessagesHelper.GetOutboxMessages(connection);

            Assert.That(messagesList.Count, Is.EqualTo(1));

            var customerRegisteredNotification =
                OutboxMessagesHelper.Deserialize <CustomerRegisteredNotification>(messagesList[0]);

            Assert.That(customerRegisteredNotification.CustomerId, Is.EqualTo(new CustomerId(customer.Id)));
        }
Esempio n. 24
0
        private async Task <TreeDto> PrepareTreeWithTwoPeople()
        {
            var treeId = await CreateTree();

            var queenId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Elżbieta",
                    "II",
                    Gender.Unknown,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));


            var princeId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Filip",
                    null,
                    Gender.Male,
                    new DateTime(1921, 5, 10),
                    null,
                    "Prince",
                    "Some biography of Filip",
                    new List <Relation>
            {
                new Relation(queenId, RelationDirection.FromAddedPerson, RelationType.Mother)
            }));

            return(await QueriesExecutor.Execute(
                       new GetTreeQuery(AuthId, treeId)));
        }
Esempio n. 25
0
        public async Task CreateProfileAndTree_HappyPath_TreeIsCreated()
        {
            var userId = await CommandsExecutor.Execute(
                new CreateOrUpdateUserProfileCommand(AuthId, Mail, Name, LastName, BirthDate));

            var treeId = await CommandsExecutor.Execute(
                new CreateTreeCommand(TreeName, AuthId, Mail));

            var myTrees = await QueriesExecutor.Execute(
                new GetMyTreesQuery(AuthId));

            Assert.Single(myTrees.Trees);

            var tree = myTrees.Trees[0];

            Assert.Equal(tree.Id, treeId.Value);
            Assert.Equal(TreeName, tree.TreeName);


            var treeQuery = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, treeId));

            Assert.Equal(userId.Value, treeQuery.Owners.FirstOrDefault()?.Id);
        }
 public async Task Execute(IJobExecutionContext context)
 {
     await CommandsExecutor.Execute(new ProcessOutboxCommand());
 }
Esempio n. 27
0
        public async Task AddRelation_TwoMothers_ThrowsException()
        {
            var treeId = await CreateTree();

            var queenId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Elżbieta",
                    "II",
                    Gender.Female,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));

            var queenId2 = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Elżbieta",
                    "III",
                    Gender.Female,
                    new DateTime(1926, 4, 21),
                    null,
                    "Queen",
                    "Some biography"));


            var princeId = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Queens child",
                    null,
                    Gender.Male,
                    new DateTime(1955, 5, 10),
                    null,
                    "Prince",
                    "Some biography of Filip",
                    null));

            var princeId2 = await CommandsExecutor.Execute(
                new AddPersonCommand(
                    AuthId,
                    treeId,
                    "Queens child",
                    null,
                    Gender.Male,
                    new DateTime(1955, 5, 10),
                    null,
                    "Prince2",
                    "Some biography of Filip",
                    null));

            await CommandsExecutor.Execute(
                new AddRelationCommand(AuthId, treeId, princeId, queenId, RelationType.Mother));

            await CommandsExecutor.Execute(
                new AddRelationCommand(AuthId, treeId, princeId2, queenId, RelationType.Mother));

            var tree = await QueriesExecutor.Execute(
                new GetTreeQuery(AuthId, treeId));

            Assert.NotNull(tree.People.First(p => p.Id == princeId.Value).Mother);
            Assert.Equal(2, tree.People.First(p => p.Id == queenId.Value).Children.Count);

            await Assert.ThrowsAsync <BusinessRuleValidationException>(async() =>
                                                                       await CommandsExecutor.Execute(
                                                                           new AddRelationCommand(AuthId, treeId, princeId, queenId, RelationType.Mother)));
        }
 public async Task <TResult> ExecuteCommandAsync <TResult>(ICommand <TResult> command)
 {
     return(await CommandsExecutor.Execute(command));
 }
 public async Task ExecuteCommandAsync(ICommand command)
 {
     await CommandsExecutor.Execute(command);
 }
Esempio n. 30
0
 public async Task Execute(IJobExecutionContext context)
 {
     await CommandsExecutor.Execute(new SyncTeamsCommand());
 }