Пример #1
0
        public void SetNewInvalidDeviceTrackerThrows()
        {
            var testEntry = this.CreateTestEntry(out _, out _, out var _, out _, out _);

            Assert.Throws <InvalidOperationException>(
                () => testEntry.DeviceTrackers.Add(MockHelpers.GetRandomEntityId(KnownDomains.Camera)));
        }
Пример #2
0
 private InputBoolean CreateTestEntry(out string entityId, out string name, out string icon, out bool initial)
 {
     entityId = MockHelpers.GetRandomEntityId(KnownDomains.InputBoolean);
     name     = MockHelpers.GetRandomTestName();
     icon     = "mdi:fan";
     initial  = true;
     return(InputBoolean.CreateUnmodified(entityId, name, icon, initial));
 }
Пример #3
0
 private Device CreateTestEntry(out string entityId, out string name, out string areaId, out DisabledByEnum disabledBy)
 {
     entityId   = MockHelpers.GetRandomEntityId(KnownDomains.Esphome);
     name       = MockHelpers.GetRandomTestName();
     areaId     = MockHelpers.GetRandomTestName();
     disabledBy = DisabledByEnum.Integration;
     return(Device.CreateUnmodified(entityId, name, areaId, disabledBy));
 }
 private EntityRegistryEntry CreateTestEntry(out string entityId, out string name, out string icon, out DisabledByEnum disabledBy)
 {
     entityId   = MockHelpers.GetRandomEntityId(KnownDomains.InputBoolean);
     name       = MockHelpers.GetRandomTestName();
     icon       = "mdi:camera";
     disabledBy = DisabledByEnum.Integration;
     return(EntityRegistryEntry.CreateUnmodified(entityId, name, icon, disabledBy));
 }
Пример #5
0
 private Person CreateTestEntry(out string entityId, out string name, out User user, out string picture, out IEnumerable <string> deviceTrackers)
 {
     entityId       = MockHelpers.GetRandomEntityId(KnownDomains.Person);
     name           = MockHelpers.GetRandomTestName();
     user           = User.CreateUnmodified(MockHelpers.GetRandomTestName(), name, false);
     picture        = "/test/Picture.png";
     deviceTrackers = new[] { MockHelpers.GetRandomEntityId(KnownDomains.DeviceTracker), MockHelpers.GetRandomEntityId(KnownDomains.DeviceTracker) };
     return(Person.CreateUnmodified(entityId, name, user.Id, picture, deviceTrackers));
 }
Пример #6
0
        public void SetNewDeviceTrackerMakesHasPendingChangesTrue()
        {
            var testDeviceTracker = MockHelpers.GetRandomEntityId(KnownDomains.DeviceTracker);
            var testEntry         = this.CreateTestEntry(out _, out _, out _, out _, out var deviceTrackers);

            testEntry.DeviceTrackers.Add(testDeviceTracker);
            Assert.IsTrue(testEntry.HasPendingChanges);

            testEntry.DeviceTrackers.Remove(testDeviceTracker);
            Assert.False(testEntry.HasPendingChanges);
        }
        private ModifiablePropertyCollection <string> CreateCollectionProperty(int elementCount = 2, Func <string, bool> validationFunc = null, bool hasChanges = false, [CallerMemberName] string collectionName = null)
        {
            var collection = new ModifiablePropertyCollection <string>(collectionName, validationFunc);

            for (int i = 0; i < elementCount; i++)
            {
                collection.Value.Add(MockHelpers.GetRandomEntityId(KnownDomains.Climate));
            }

            if (!hasChanges)
            {
                collection.SaveChanges();
            }

            return(collection);
        }
Пример #8
0
        public void DiscardPendingChanges()
        {
            var testEntry = this.CreateTestEntry(out _, out var initialName, out var initialUser, out var initialPicture, out var initialDeviceTrackers);

            testEntry.Name = MockHelpers.GetRandomTestName();
            testEntry.ChangeUser(this.testUser);
            testEntry.Picture = $"/test/{MockHelpers.GetRandomTestName()}.png";
            testEntry.DeviceTrackers.Add(MockHelpers.GetRandomEntityId(KnownDomains.DeviceTracker));
            Assert.IsTrue(testEntry.HasPendingChanges);

            testEntry.DiscardPendingChanges();
            Assert.False(testEntry.HasPendingChanges);
            Assert.AreEqual(initialName, testEntry.Name);
            Assert.AreEqual(initialUser.Id, testEntry.UserId);
            Assert.AreEqual(initialPicture, testEntry.Picture);
            Assert.AreEqual(initialDeviceTrackers, testEntry.DeviceTrackers);
        }