public async void ShouldReturnVoidedStatement()
        {
            // Arrange
            var mediatorMock  = new Mock <IMediator>();
            var authorityMock = new Mock <IClientContext>();

            var createStatementHandler = new CreateStatementCommandHandler(_context, mediatorMock.Object, _mapper, authorityMock.Object);

            var voidStatementQueryHandler = new VoidedStatemetQueryHandler(_context, _mapper);
            var voidedStatementId         = Guid.Parse("637E9E80-4B8D-4640-AC13-615C3E413568");

            var statement = new Statement("{\"actor\":{\"objectType\":\"Agent\",\"name\":\"xAPI mbox\",\"mbox\":\"mailto:[email protected]\"},\"verb\":{\"id\":\"http://adlnet.gov/expapi/verbs/attended\",\"display\":{\"en-GB\":\"attended\",\"en-US\":\"attended\"}},\"object\":{\"objectType\":\"Activity\",\"id\":\"http://www.example.com/meetings/occurances/34534\"}}");

            statement.Id = voidedStatementId;

            var voidingStatement = new Statement()
            {
                Actor = new Agent()
                {
                    Mbox = new Mbox("mailto:[email protected]")
                },
                Verb = new Verb()
                {
                    Id = new Iri("http://adlnet.gov/expapi/verbs/voided")
                },
                Object = new StatementRef()
                {
                    Id = voidedStatementId
                },
            };

            voidingStatement.Object.As <StatementRef>().Id = statement.Id.Value;

            // Act
            Guid statementId = await createStatementHandler.Handle(
                CreateStatementCommand.Create(statement),
                CancellationToken.None
                );

            // Create voiding statement
            Guid voidingStatementId = await createStatementHandler.Handle(
                CreateStatementCommand.Create(voidingStatement),
                CancellationToken.None
                );

            // Query voided statement
            StatementEntity voidedStatement = await voidStatementQueryHandler.Handle(
                VoidedStatemetQuery.Create(voidedStatementId),
                CancellationToken.None
                );

            // Assert
            mediatorMock.Verify(m => m.Publish(It.IsAny <StatementCreated>(), It.IsAny <CancellationToken>()), Times.AtLeast(2));
            voidedStatement.ShouldNotBe(null);
            voidedStatement.VoidingStatementId.ShouldBe(voidingStatementId);
        }
Beispiel #2
0
        public async void ShouldRaiseStatementCreatingNotification()
        {
            // Arrange
            var mediatorMock  = new Mock <IMediator>();
            var authorityMock = new Mock <IClientContext>();

            var       sut       = new CreateStatementCommandHandler(_context, mediatorMock.Object, _mapper, authorityMock.Object);
            Statement statement = GetStatement(Guid.NewGuid());

            // Act
            var result = await sut.Handle(CreateStatementCommand.Create(statement), CancellationToken.None);

            // Assert
            mediatorMock.Verify(m => m.Publish(
                                    It.IsAny <StatementCreating>(),
                                    It.IsAny <CancellationToken>()),
                                Times.Once);
        }
Beispiel #3
0
        public async void Handle_GivenValidRequest_ShouldRaiseStatementCreatedNotification()
        {
            // Arrange
            var mediatorMock  = new Mock <IMediator>();
            var authorityMock = new Mock <IClientContext>();

            var       createStatement = new CreateStatementCommandHandler(_context, mediatorMock.Object, _mapper, authorityMock.Object);
            Guid      newStatementId  = Guid.NewGuid();
            Statement statement       = GetStatement(newStatementId);

            // Act
            var result = await createStatement.Handle(CreateStatementCommand.Create(statement), CancellationToken.None);

            // Assert
            mediatorMock.Verify(m => m.Publish(
                                    It.Is <StatementCreated>(cc => cc.Created.StatementId == newStatementId),
                                    It.IsAny <CancellationToken>()),
                                Times.Once);
        }