Exemplo n.º 1
0
 public async Task GetTags_ShouldFailWhenHistorianIsNotInitialized()
 {
     await Assert.ThrowsAsync <InvalidOperationException>(() => {
         var historian = _fixture.CreateHistorian();
         return(historian.GetTags(Identities.GetTestIdentity(), new[] { "First_Test_Tag", "Second_Test_Tag" }, CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 2
0
        public override async Task InitializeAsync()
        {
            await base.InitializeAsync().ConfigureAwait(false);

            TagDefinition t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name        = "DeleteTag_Target",
                Description = "This is the first test tag",
                Units       = "km/h"
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name        = "UpdateTag_Target",
                Description = "This is the second test tag",
                Units       = "deg C"
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;
        }
Exemplo n.º 3
0
        public async Task DeleteTag_DeleteByTagIdShouldReturnTrue()
        {
            var tag    = _fixture.TagMap.Values.First(x => x.Name.Equals("DeleteTag_Target"));
            var result = await _fixture.DefaultHistorian.DeleteTag(Identities.GetTestIdentity(), tag.Id, CancellationToken.None).ConfigureAwait(false);

            Assert.True(result);
        }
Exemplo n.º 4
0
 public async Task FindTags_ShouldFailWhenFilterIsNull()
 {
     await Assert.ThrowsAsync <ArgumentNullException>(() => {
         return(_fixture.DefaultHistorian.FindTags(Identities.GetTestIdentity(),
                                                   null,
                                                   CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 5
0
        public async Task UpdateTag_DescriptionShouldBeUpdated()
        {
            var tag            = _fixture.TagMap.Values.First(x => x.Name.Equals("UpdateTag_Target"));
            var newDescription = nameof(UpdateTag_DescriptionShouldBeUpdated);

            var updatedTag = await _fixture.DefaultHistorian.UpdateTag(Identities.GetTestIdentity(), tag.Id, new TagSettings()
            {
                Description = newDescription
            }, nameof(UpdateTag_ShouldFailWhenTagIdDoesNotExist), CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(newDescription, updatedTag.Description);
        }
Exemplo n.º 6
0
 public async Task CreateTag_ShouldFailWhenNameIsNullOrWhiteSpace(string name)
 {
     await Assert.ThrowsAsync <ArgumentException>(() => {
         return(_fixture.DefaultHistorian
                .CreateTag(Identities.GetTestIdentity(),
                           new TagSettings()
         {
             Name = name,
             Description = "This is a test tag",
             Units = "km/h"
         }, CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 7
0
 public async Task CreateTag_ShouldFailWhenHistorianIsNotInitialized()
 {
     await Assert.ThrowsAsync <InvalidOperationException>(() => {
         return(_fixture.CreateHistorian()
                .CreateTag(Identities.GetTestIdentity(),
                           new TagSettings()
         {
             Name = nameof(CreateTag_ShouldFailWhenHistorianIsNotInitialized),
             Description = "This is a test tag",
             Units = "km/h"
         }, CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 8
0
        public async Task WriteMultipleFloatValues_ShouldUpdateSnapshotValueAndRecordHistory()
        {
            var tag    = _fixture.TagMap.Values.First(x => x.Name.Equals("WriteMultipleFloatValues_Target"));
            var values = Enumerable.Range(0, 10).Select(x => new TagValue(DateTime.UtcNow.AddHours(-1 * x), 100 - x, null, TagValueQuality.Good, null)).OrderBy(x => x.UtcSampleTime).ToArray();

            var writeResult = await _fixture.DefaultHistorian.WriteTagData(Identities.GetTestIdentity(), new Dictionary <string, IEnumerable <TagValue> >() {
                { tag.Name, values }
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.Single(writeResult);
            Assert.Contains(writeResult, x => x.Key.Equals(tag.Name));
            Assert.Equal(values.Length, writeResult.First().Value.SampleCount);
            Assert.Equal(values.First().UtcSampleTime, writeResult.First().Value.UtcEarliestSampleTime);
            Assert.Equal(values.Last().UtcSampleTime, writeResult.First().Value.UtcLatestSampleTime);
        }
Exemplo n.º 9
0
        public async Task FindTags_ShouldReturnZeroTags()
        {
            var tags = await _fixture.DefaultHistorian.FindTags(Identities.GetTestIdentity(),
                                                                new TagDefinitionFilter()
            {
                FilterClauses = new[] {
                    new TagDefinitionFilterClause()
                    {
                        Field = TagDefinitionFilterField.Name,
                        Value = "SHOULD_NOT_MATCH"
                    }
                }
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.Empty(tags);
        }
Exemplo n.º 10
0
        public async Task FindTags_ShouldFindTagsByUnitFilter(string filter, string expectedResult)
        {
            var tags = await _fixture.DefaultHistorian.FindTags(Identities.GetTestIdentity(),
                                                                new TagDefinitionFilter()
            {
                FilterClauses = new[] {
                    new TagDefinitionFilterClause()
                    {
                        Field = TagDefinitionFilterField.Units,
                        Value = filter
                    }
                }
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.Single(tags);
            Assert.Equal(tags.First().Name, expectedResult);
        }
Exemplo n.º 11
0
 public async Task FindTags_ShouldFailWhenHistorianIsNotInitialized()
 {
     await Assert.ThrowsAsync <InvalidOperationException>(() => {
         var historian = _fixture.CreateHistorian();
         return(historian.FindTags(Identities.GetTestIdentity(),
                                   new TagDefinitionFilter()
         {
             FilterClauses = new[] {
                 new TagDefinitionFilterClause()
                 {
                     Field = TagDefinitionFilterField.Name,
                     Value = "*"
                 }
             }
         }, CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 12
0
        public async Task WriteSingleFloatValue_ShouldUpdateSnapshotValue()
        {
            var tag    = _fixture.TagMap.Values.First(x => x.Name.Equals("WriteSingleFloatValue_Target"));
            var values = new[] {
                new TagValue(DateTime.UtcNow, 100, null, TagValueQuality.Good, null)
            };

            var writeResult = await _fixture.DefaultHistorian.WriteTagData(Identities.GetTestIdentity(), new Dictionary <string, IEnumerable <TagValue> >() {
                { tag.Name, values }
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.Single(writeResult);
            Assert.Contains(writeResult, x => x.Key.Equals(tag.Name));
            Assert.Equal(1, writeResult.First().Value.SampleCount);
            Assert.Equal(values.First().UtcSampleTime, writeResult.First().Value.UtcEarliestSampleTime);
            Assert.Equal(values.First().UtcSampleTime, writeResult.First().Value.UtcEarliestSampleTime);
            Assert.Equal(values.First(), tag.ReadSnapshotValue(Identities.GetTestIdentity()));
        }
Exemplo n.º 13
0
        public async Task CreateTag_ShouldReturnNewTag()
        {
            var initialTagCount = (await _fixture.DefaultHistorian.FindTags(Identities.GetTestIdentity(), new TagDefinitionFilter(), CancellationToken.None).ConfigureAwait(false)).Count();

            var tag = await _fixture.DefaultHistorian
                      .CreateTag(Identities.GetTestIdentity(),
                                 new TagSettings()
            {
                Name        = nameof(CreateTag_ShouldReturnNewTag),
                Description = "This is a test tag",
                Units       = "km/h"
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.NotNull(tag);
            Assert.Equal(_fixture.DefaultHistorian.Historian, tag.Historian);

            var tags = await _fixture.DefaultHistorian.FindTags(Identities.GetTestIdentity(), new TagDefinitionFilter(), CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(initialTagCount + 1, tags.Count());
        }
Exemplo n.º 14
0
 public async Task GetTags_ShouldFailWhenListContainsOnlyBlankValues()
 {
     await Assert.ThrowsAsync <ArgumentException>(() => {
         return(_fixture.DefaultHistorian.GetTags(Identities.GetTestIdentity(), new[] { "", " ", "   " }, CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 15
0
        public async Task GetTags_ShouldReturnTagsByName()
        {
            var tags = await _fixture.DefaultHistorian.GetTags(Identities.GetTestIdentity(), new[] { "First_Test_Tag", "Second_Test_Tag" }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(2, tags.Count);
        }
Exemplo n.º 16
0
        public override async Task InitializeAsync()
        {
            await base.InitializeAsync().ConfigureAwait(false);

            TestStateSet = await DefaultHistorian.CreateStateSet(Identities.GetTestIdentity(), new StateSetSettings()
            {
                Name        = "TestStateSet",
                Description = "Contains states used in tag data write tests",
                States      = new [] {
                    new StateSetItem("OFF", 0),
                    new StateSetItem("ON", 1)
                }
            }, CancellationToken.None).ConfigureAwait(false);

            TagDefinition t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteSingleFloatValue_Target",
                DataType = TagDataType.FloatingPoint
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteMultipleFloatValues_Target",
                DataType = TagDataType.FloatingPoint
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteSingleIntValue_Target",
                DataType = TagDataType.Integer
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteMultipleIntValues_Target",
                DataType = TagDataType.Integer
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteSingleTextValue_Target",
                DataType = TagDataType.Text
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteMultipleTextValues_Target",
                DataType = TagDataType.Text
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteSingleStateValue_Target",
                StateSet = TestStateSet.Name,
                DataType = TagDataType.State
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;

            t = await DefaultHistorian.CreateTag(Identities.GetTestIdentity(),
                                                 new TagSettings()
            {
                Name     = "WriteMultipleStateValues_Target",
                StateSet = TestStateSet.Name,
                DataType = TagDataType.State
            }, CancellationToken.None).ConfigureAwait(false);

            TagMap[t.Id] = t;
        }
Exemplo n.º 17
0
 public async Task UpdateTag_ShouldFailWhenTagIdDoesNotExist()
 {
     await Assert.ThrowsAsync <ArgumentException>(() => {
         return(_fixture.DefaultHistorian.UpdateTag(Identities.GetTestIdentity(), Guid.Empty.ToString(), new TagSettings(), nameof(UpdateTag_ShouldFailWhenTagIdDoesNotExist), CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 18
0
 public async Task UpdateTag_ShouldFailWhenTagIdIsNullOrWhiteSpace(string name)
 {
     await Assert.ThrowsAsync <ArgumentException>(() => {
         return(_fixture.DefaultHistorian.UpdateTag(Identities.GetTestIdentity(), name, new TagSettings(), nameof(UpdateTag_ShouldFailWhenTagIdIsNullOrWhiteSpace), CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 19
0
        public async Task GetTags_ShouldReturnTagsById()
        {
            var tags = await _fixture.DefaultHistorian.GetTags(Identities.GetTestIdentity(), _fixture.TagMap.Keys, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(2, tags.Count);
        }
Exemplo n.º 20
0
        public async Task DeleteTag_ShouldReturnFalseWhenTagIdOrNameDoesNotExist()
        {
            var result = await _fixture.DefaultHistorian.DeleteTag(Identities.GetTestIdentity(), Guid.Empty.ToString(), CancellationToken.None).ConfigureAwait(false);

            Assert.False(result);
        }
Exemplo n.º 21
0
 public async Task GetTags_ShouldFailWhenListIsEmpty()
 {
     await Assert.ThrowsAsync <ArgumentException>(() => {
         return(_fixture.DefaultHistorian.GetTags(Identities.GetTestIdentity(), new string[0], CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 22
0
 public async Task DeleteTag_ShouldFailWhenHistorianIsNotInitialized()
 {
     await Assert.ThrowsAsync <InvalidOperationException>(() => {
         return(_fixture.CreateHistorian().DeleteTag(Identities.GetTestIdentity(), Guid.Empty.ToString(), CancellationToken.None));
     }).ConfigureAwait(false);
 }
Exemplo n.º 23
0
        public async Task GetTags_ShouldNotReturnDuplicates()
        {
            var tags = await _fixture.DefaultHistorian.GetTags(Identities.GetTestIdentity(), new[] { "First_Test_Tag", "First_Test_Tag" }, CancellationToken.None).ConfigureAwait(false);

            Assert.Single(tags);
        }