Esempio n. 1
0
        public Task <ActionResult> EditMessage(EditStatusEventMessage model)
        {
            var startTime = ParseModelDateTime(model.StartTime);
            var timestamp = ParseModelDateTime(model.Timestamp);

            ManualStatusChangeEntity entity;

            if (model.Delete)
            {
                entity = new DeleteStatusMessageManualChangeEntity(
                    model.AffectedComponentPath,
                    startTime,
                    timestamp);
            }
            else
            {
                entity = new EditStatusMessageManualChangeEntity(
                    model.AffectedComponentPath,
                    startTime,
                    timestamp,
                    model.EditMessage);
            }

            return(RunUpdateStatusTask(entity));
        }
            public async Task ThrowsArgumentExceptionIfMissingEvent()
            {
                var entity = new EditStatusMessageManualChangeEntity("path", new DateTime(2018, 8, 20), new DateTime(2018, 8, 21), "message");

                var eventRowKey = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime);

                _table
                .Setup(x => x.RetrieveAsync <EventEntity>(eventRowKey))
                .Returns(Task.FromResult <EventEntity>(null));

                await Assert.ThrowsAsync <ArgumentException>(() => _handler.Handle(entity));
            }
            public async Task EditsMessage(MessageType type)
            {
                var entity = new EditStatusMessageManualChangeEntity("path", new DateTime(2018, 8, 20), new DateTime(2018, 8, 21), "message");

                var eventRowKey   = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime);
                var messageRowKey = MessageEntity.GetRowKey(eventRowKey, entity.MessageTimestamp);

                var existingEntity =
                    new EventEntity(
                        entity.EventAffectedComponentPath,
                        entity.EventStartTime,
                        ComponentStatus.Up,
                        null);

                _table
                .Setup(x => x.RetrieveAsync <EventEntity>(eventRowKey))
                .Returns(Task.FromResult(existingEntity));

                var existingMessage = new MessageEntity(
                    existingEntity,
                    entity.MessageTimestamp,
                    "old message",
                    type);

                _table
                .Setup(x => x.RetrieveAsync <MessageEntity>(messageRowKey))
                .Returns(Task.FromResult(existingMessage));

                _table
                .Setup(x => x.ReplaceAsync(
                           It.Is <MessageEntity>(messageEntity =>
                                                 messageEntity.PartitionKey == MessageEntity.DefaultPartitionKey &&
                                                 messageEntity.RowKey == messageRowKey &&
                                                 messageEntity.ParentRowKey == eventRowKey &&
                                                 messageEntity.Time == existingMessage.Time &&
                                                 messageEntity.Contents == entity.MessageContents &&
                                                 messageEntity.Type == (int)MessageType.Manual
                                                 )))
                .Returns(Task.CompletedTask)
                .Verifiable();

                await _handler.Handle(entity);

                _table.Verify();
            }