public async Task SavesNewMessageAndUpdatesEventIfNecessary(bool eventIsActive, bool shouldEventBeActive)
            {
                var eventStartTime = new DateTime(2018, 8, 19);
                var entity         = new AddStatusMessageManualChangeEntity("path", eventStartTime, "message", shouldEventBeActive)
                {
                    Timestamp = new DateTimeOffset(2018, 8, 21, 0, 0, 0, TimeSpan.Zero)
                };

                var time           = entity.Timestamp.UtcDateTime;
                var existingEntity =
                    new EventEntity(
                        entity.EventAffectedComponentPath,
                        eventStartTime,
                        ComponentStatus.Up,
                        eventIsActive ? (DateTime?)null : new DateTime(2018, 8, 20));

                var eventRowKey = existingEntity.RowKey;

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

                _table
                .Setup(x => x.InsertAsync(It.IsAny <MessageEntity>()))
                .Returns(Task.CompletedTask);

                _table
                .Setup(x => x.ReplaceAsync(It.IsAny <EventEntity>()))
                .Returns(Task.CompletedTask);

                await _handler.Handle(entity);

                _table
                .Verify(
                    x => x.InsertAsync(
                        It.Is <MessageEntity>(message =>
                                              message.PartitionKey == MessageEntity.DefaultPartitionKey &&
                                              message.RowKey == MessageEntity.GetRowKey(eventRowKey, time) &&
                                              message.ParentRowKey == eventRowKey &&
                                              message.Time == time &&
                                              message.Contents == entity.MessageContents
                                              )),
                    Times.Once());

                var shouldEventBeUpdated = ManualStatusChangeUtility.ShouldEventBeActive(existingEntity, shouldEventBeActive, time);

                _table
                .Verify(
                    x => x.InsertAsync(
                        It.Is <EventEntity>(eventEntity =>
                                            eventEntity.PartitionKey == EventEntity.DefaultPartitionKey &&
                                            eventEntity.RowKey == eventRowKey &&
                                            eventEntity.AffectedComponentPath == existingEntity.AffectedComponentPath &&
                                            eventEntity.AffectedComponentStatus == existingEntity.AffectedComponentStatus &&
                                            eventEntity.StartTime == time
                                            )),
                    shouldEventBeUpdated ? Times.Once() : Times.Never());
            }
Пример #2
0
            public async Task EditsEvent(bool eventIsActive, bool shouldEventBeActive)
            {
                var entity = new EditStatusEventManualChangeEntity("path", ComponentStatus.Degraded, new DateTime(2018, 8, 20), shouldEventBeActive)
                {
                    Timestamp = new DateTimeOffset(2018, 8, 21, 0, 0, 0, TimeSpan.Zero)
                };

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

                var existingEntity =
                    new EventEntity(
                        entity.EventAffectedComponentPath,
                        entity.EventStartTime,
                        ComponentStatus.Up,
                        eventIsActive ? (DateTime?)null : new DateTime(2018, 8, 19));

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

                var shouldUpdateEndTime = ManualStatusChangeUtility.ShouldEventBeActive(existingEntity, shouldEventBeActive, time);

                _table
                .Setup(x => x.ReplaceAsync(
                           It.Is <EventEntity>(eventEntity =>
                                               eventEntity.PartitionKey == EventEntity.DefaultPartitionKey &&
                                               eventEntity.RowKey == eventRowKey &&
                                               eventEntity.AffectedComponentPath == existingEntity.AffectedComponentPath &&
                                               eventEntity.AffectedComponentStatus == entity.EventAffectedComponentStatus &&
                                               eventEntity.StartTime == existingEntity.StartTime &&
                                               eventEntity.EndTime == (shouldUpdateEndTime ? time : existingEntity.EndTime)
                                               )))
                .Returns(Task.CompletedTask)
                .Verifiable();

                await _handler.Handle(entity);

                _table.Verify();
            }
 protected override bool GetResult(EventEntity eventEntity, bool eventIsActive, DateTime timestamp)
 {
     return(ManualStatusChangeUtility.ShouldEventBeActive(eventEntity, eventIsActive, timestamp));
 }