Esempio n. 1
0
        public void Add_ArgNullTest()
        {
            // arrange
            MultiCollection <int, string, Person> collection = new MultiCollection <int, string, Person>();

            // assert
            Assert.ThrowsException <ArgumentNullException>(() => collection.Add(1, null, null));
        }
Esempio n. 2
0
        public void Add_DuplicateTest()
        {
            // arrange
            MultiCollection <int, string, DateTime> collection = new MultiCollection <int, string, DateTime>();

            int    testId   = 1;
            string testName = Guid.NewGuid().ToString();
            var    val      = DateTime.Now;

            // act
            collection.Add(testId, testName, val);
            collection.Add(testId, testName, val);
            // assert
            Assert.AreEqual(collection.Values.ToList()[0], val);
        }
Esempio n. 3
0
        public void AddTest()
        {
            // arrange
            MultiCollection <int, int, int> collection = new MultiCollection <int, int, int>();
            int numCnt = 100;

            // act
            for (int i = 0; i < numCnt; i++)
            {
                collection.Add(i, i, i);
            }

            // assert
            Assert.AreEqual(collection.Count, numCnt);
        }
Esempio n. 4
0
        public void Identical_Types_In_Key_Test()
        {
            MultiCollection <int, int, Person> dcCollection = new MultiCollection <int, int, Person>();

            dcCollection.Add(75, 75, new Person());
            dcCollection.Add(17, 21, new Person());
            dcCollection.Add(11, 2, new Person());
            dcCollection.Add(75, 4, new Person());

            var resultId = dcCollection[id : 75];

            Assert.AreEqual(2, resultId.Count());
            var resultName = dcCollection[name : 75];

            Assert.AreEqual(1, resultName.Count());
        }
Esempio n. 5
0
        public void Contains_Name_UserTypes_Test()
        {
            // Arrange
            var utCollection = new MultiCollection <IdKey, NameKey, Person>();

            // 1 Значение
            var idType  = new IdKey(1);
            var idValue = idType.Id;

            var nameType  = new NameKey("A");
            var nameValue = nameType.Name;

            var personType       = new Person(idValue, nameValue);
            var personIdValue    = personType.Id;
            var personNotesValue = personType.Notes;

            // 2 Значение
            var idType2  = new IdKey(2);
            var idValue2 = idType2.Id;

            var nameType2  = new NameKey("B");
            var nameValue2 = nameType2.Name;

            var personType2       = new Person(idValue2, nameValue2);
            var personIdValue2    = personType2.Id;
            var personNotesValue2 = personType2.Notes;

            utCollection.Clear();
            utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue));
            utCollection.Add(new IdKey(idValue2), new NameKey(nameValue2), new Person(idValue2, nameValue2));

            // Action
            var newNameKey        = new NameKey(nameValue);
            var isContainsByValue = utCollection.Contains(newNameKey);
            var isContainsByRef   = utCollection.Contains(nameType);

            var hCodeId  = newNameKey.GetHashCode();
            var hcIdType = nameType.GetHashCode();

            // Assert
            Assert.IsFalse(utCollection.Contains(new NameKey("C")));
            Assert.AreEqual(hcIdType, hCodeId);
            Assert.IsTrue(isContainsByValue);
            Assert.IsTrue(isContainsByRef);
        }
Esempio n. 6
0
        public void Struct_Test()
        {
            // Arrange
            var dict = new Dictionary <MultiCollection <IdKey, NameKey, Person> .KeyStruct, Person>();

            dict.Add(new MultiCollection <IdKey, NameKey, Person> .KeyStruct(new IdKey(1), new NameKey("A")), new Person(1, "A"));
            dict.Add(new MultiCollection <IdKey, NameKey, Person> .KeyStruct(new IdKey(2), new NameKey("B")), new Person());
            // Action
            var containsKey = dict.ContainsKey(new MultiCollection <IdKey, NameKey, Person> .KeyStruct(new IdKey(1), new NameKey("A")));

            // Assert
            Assert.IsTrue(containsKey);
            var str = new MultiCollection <IdKey, NameKey, Person> .KeyStruct(new IdKey(2), new NameKey("B"));

            var containsStr = dict.Keys.Contains(new MultiCollection <IdKey, NameKey, Person> .KeyStruct(str));

            Assert.IsTrue(containsStr);
        }
Esempio n. 7
0
        public void Setup()
        {
            // Стандартная коллекция с простыми типами
            _stdCollection = new MultiCollection <int, string, Person>();

            _person1 = new Person();
            _person2 = new Person();
            _person3 = new Person();

            _stdCollection.Add(_person1.Id, _person1.Notes, _person1);
            _stdCollection.Add(_person2.Id, _person2.Notes, _person2);
            _stdCollection.Add(_person3.Id, _person3.Notes, _person3);

            // Коллекция с сложными ключами
            _userTypeCollection = new MultiCollection <IdKey, NameKey, Person>();
            _idKey1             = new IdKey(1);
            _nameKey1           = new NameKey("A");
            _personUt1          = new Person(_idKey1.Id, _nameKey1.Name);
            _userTypeCollection.Add(_idKey1, _nameKey1, _personUt1);
        }
Esempio n. 8
0
        public void Contains_Value_UserTypes_Test()
        {
            // Arrange
            var utCollection = new MultiCollection <IdKey, NameKey, Person>();

            // 1 Значение
            var idType  = new IdKey(1);
            var idValue = idType.Id;

            var nameType  = new NameKey("A");
            var nameValue = nameType.Name;

            var personType       = new Person(idValue, nameValue);
            var personIdValue    = personType.Id;
            var personNotesValue = personType.Notes;

            // 2 Значение
            var idType2  = new IdKey(2);
            var idValue2 = idType2.Id;

            var nameType2  = new NameKey("B");
            var nameValue2 = nameType2.Name;

            var personType2       = new Person(idValue2, nameValue2);
            var personIdValue2    = personType2.Id;
            var personNotesValue2 = personType2.Notes;

            utCollection.Clear();
            utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue));
            utCollection.Add(idType2, nameType2, personType2);

            // Action
            var isContainsByValue = utCollection.Contains(new Person(idValue2, nameValue2));
            var isContainsByRef   = utCollection.Contains(personType2);

            // Assert
            Assert.IsTrue(isContainsByValue);
            Assert.IsTrue(isContainsByRef);
        }
Esempio n. 9
0
        public void SpeedTest_Reference_Type_Key_Get_Value_Test()
        {
            //Arrange
            Stopwatch stopWatch    = new Stopwatch();
            var       collection   = new MultiCollection <IdKey, NameKey, Person>();
            var       expectedName = new NameKey("AA");

            // Init Expected values
            for (int i = 0; i < 15; i++)
            {
                var p = new Person();
                collection.Add(new IdKey(i), expectedName, p);
            }

            // Init random entries
            for (int i = 500; i < 100000; i++)
            {
                var person = new Person();
                collection.Add(new IdKey(i), new NameKey(), person);
            }


            //Action
            stopWatch.Start();
            var result        = collection[expectedName];
            var actualdLength = result.Count();

            stopWatch.Stop();

            var time = stopWatch.Elapsed.TotalMilliseconds; // Key Value

            // Key Struct     32.53
            // Key Struct std 26.0053
            // ValueTuple 24.7
            // Tuple 14
            //Assert
            Assert.AreEqual(15, actualdLength);
        }
Esempio n. 10
0
        public void Index_Id_Name_UserTypes_Test()
        {
            // Arrange
            var utCollection = new MultiCollection <IdKey, NameKey, Person>();

            // 1 Значение
            var idType  = new IdKey(1);
            var idValue = idType.Id;

            var nameType  = new NameKey("A");
            var nameValue = nameType.Name;

            var personType       = new Person(idValue, nameValue);
            var personIdValue    = personType.Id;
            var personNotesValue = personType.Notes;

            // 2 Значение
            var idType2  = new IdKey(2);
            var idValue2 = idType2.Id;

            var nameType2  = new NameKey("B");
            var nameValue2 = nameType2.Name;

            var personType2       = new Person(idValue2, nameValue2);
            var personIdValue2    = personType2.Id;
            var personNotesValue2 = personType2.Notes;

            utCollection.Clear();
            utCollection.Add(new IdKey(idValue), new NameKey(nameValue), new Person(idValue, nameValue));
            utCollection.Add(idType2, nameType2, personType2);

            // Action
            var actualPerson = utCollection[new IdKey(idValue), new NameKey(nameValue)];

            // Assert
            Assert.AreEqual(personType.Id, actualPerson.Id);
            Assert.AreEqual(personType.Notes, actualPerson.Notes);
        }
Esempio n. 11
0
 public void TakeFromTXTFile(string locationFile)
 {
     _textFactory = new TxtFile(locationFile, DataManager);
     _textFactory.Populate();
     Multi = _textFactory._multi;
 }
Esempio n. 12
0
    private async Task <Unit> ApplyUpdateRequest(TvContext dbContext, MultiCollection c, UpdateMultiCollection request)
    {
        c.Name = request.Name;

        // save name first so playouts don't get rebuilt for a name change
        await dbContext.SaveChangesAsync();

        var toAdd = request.Items
                    .Filter(i => i.CollectionId.HasValue)
                    // ReSharper disable once PossibleInvalidOperationException
                    .Filter(i => c.MultiCollectionItems.All(i2 => i2.CollectionId != i.CollectionId.Value))
                    .Map(
            i => new MultiCollectionItem
        {
            // ReSharper disable once PossibleInvalidOperationException
            CollectionId      = i.CollectionId.Value,
            MultiCollectionId = c.Id,
            ScheduleAsGroup   = i.ScheduleAsGroup,
            PlaybackOrder     = i.PlaybackOrder
        })
                    .ToList();
        var toRemove = c.MultiCollectionItems
                       .Filter(i => request.Items.All(i2 => i2.CollectionId != i.CollectionId))
                       .ToList();

        // remove items that are no longer present
        c.MultiCollectionItems.RemoveAll(toRemove.Contains);

        // update existing items
        foreach (MultiCollectionItem item in c.MultiCollectionItems)
        {
            foreach (UpdateMultiCollectionItem incoming in request.Items.Filter(
                         i => i.CollectionId == item.CollectionId))
            {
                item.ScheduleAsGroup = incoming.ScheduleAsGroup;
                item.PlaybackOrder   = incoming.PlaybackOrder;
            }
        }

        // add new items
        c.MultiCollectionItems.AddRange(toAdd);

        var toAddSmart = request.Items
                         .Filter(i => i.SmartCollectionId.HasValue)
                         // ReSharper disable once PossibleInvalidOperationException
                         .Filter(i => c.MultiCollectionSmartItems.All(i2 => i2.SmartCollectionId != i.SmartCollectionId.Value))
                         .Map(
            i => new MultiCollectionSmartItem
        {
            // ReSharper disable once PossibleInvalidOperationException
            SmartCollectionId = i.SmartCollectionId.Value,
            MultiCollectionId = c.Id,
            ScheduleAsGroup   = i.ScheduleAsGroup,
            PlaybackOrder     = i.PlaybackOrder
        })
                         .ToList();
        var toRemoveSmart = c.MultiCollectionSmartItems
                            .Filter(i => request.Items.All(i2 => i2.SmartCollectionId != i.SmartCollectionId))
                            .ToList();

        // remove items that are no longer present
        c.MultiCollectionSmartItems.RemoveAll(toRemoveSmart.Contains);

        // update existing items
        foreach (MultiCollectionSmartItem item in c.MultiCollectionSmartItems)
        {
            foreach (UpdateMultiCollectionItem incoming in request.Items.Filter(
                         i => i.SmartCollectionId == item.SmartCollectionId))
            {
                item.ScheduleAsGroup = incoming.ScheduleAsGroup;
                item.PlaybackOrder   = incoming.PlaybackOrder;
            }
        }

        // add new items
        c.MultiCollectionSmartItems.AddRange(toAddSmart);

        // rebuild playouts
        if (await dbContext.SaveChangesAsync() > 0)
        {
            // refresh all playouts that use this collection
            foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingMultiCollection(
                         request.MultiCollectionId))
            {
                await _channel.WriteAsync(new BuildPlayout(playoutId, PlayoutBuildMode.Refresh));
            }
        }

        return(Unit.Default);
    }
Esempio n. 13
0
 public TxtFile(string location, UODataManager data)
 {
     _location = location;
     _multi    = new MultiCollection(data);
 }