private void LoadStateIfNecessary()
 {
     if (_currentState != null)
     {
         return;
     }
     _currentState = _keyValueStore.GetValue <TState>(_incomingMessage.SagaInstanceId.ToString());
 }
Пример #2
0
        public void ShouldBeSerializableAndParseable()
        {
            var         value  = RandomString();
            HashedValue hashed = value;
            var         copy   = HashedValue.ParseFromHash(hashed.ToString());

            Assert.AreEqual(hashed, copy);
            Assert.AreEqual(copy, value);
        }
Пример #3
0
 public Account(string name, string email, string password)
 {
     Name  = name ?? throw new ArgumentNullException(nameof(name));
     Email = email;
     if (password?.Length < 8)
     {
         throw new ArgumentException(nameof(password));
     }
     PasswordHash = password;
 }
Пример #4
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Account>()
            .Property(a => a.PasswordHash)
            .HasConversion(p => p.ToString(), p => HashedValue.ParseFromHash(p));

            modelBuilder.Entity <Account>()
            .Property(a => a.Email)
            .HasConversion(p => p.ToString(), p => p);

            modelBuilder.Entity <NobreakState>()
            .HasIndex(s => s.Timestamp)
            .IsUnique();
        }
        public ISagaProcessState <TIncomingMessage, TState> InitialiseState(Func <TIncomingMessage, TState> initFunc)
        {
            TState stateInit = initFunc(_incomingMessage);

            if (stateInit.SagaInstanceId == default(Guid))
            {
                throw new SagaException("Expected InitialiseState to set SagaInstanceId");
            }
            _currentState = new HashedValue <TState>
            {
                Value = stateInit,
                Hash  = string.Empty
            };
            _needToSaveState = true;
            return(this);
        }
Пример #6
0
        public void ShouldBeVersatile()
        {
            var         value          = RandomString();
            var         differentValue = value + "-";
            HashedValue hashed         = value;

            Assert.AreEqual(hashed, value);
            Assert.AreNotEqual(differentValue, hashed);

            Assert.IsTrue(value == hashed);
            Assert.IsTrue(hashed == value);
            Assert.IsFalse(hashed != value);
            Assert.IsFalse(value != hashed);

            Assert.IsFalse(differentValue == hashed);
            Assert.IsFalse(hashed == differentValue);
            Assert.IsTrue(hashed != differentValue);
            Assert.IsTrue(differentValue != hashed);
        }
        public void DeleteShouldDeleteValidHash()
        {
            //Arrange
            string uniqueKey = Guid.NewGuid().ToString();

            _cleanupKeys.Add(uniqueKey);

            //Act

            //Create state
            _store.TrySetValue(uniqueKey, "initState", string.Empty);
            //Get current state
            HashedValue <string> value = _store.GetValue <string>(uniqueKey);

            _store.Remove(uniqueKey, value.Hash).Should().BeTrue();

            //Assert
            HashedValue <string> modifiedvalue = _store.GetValue <string>(uniqueKey);

            modifiedvalue.Value.Should().BeNull();
        }
        public void StoreShouldNotAllowOldHash()
        {
            //Arrange
            string uniqueKey = Guid.NewGuid().ToString();

            _cleanupKeys.Add(uniqueKey);

            //Act

            //Create state
            _store.TrySetValue(uniqueKey, "initState", string.Empty);
            //Get current state
            HashedValue <string> value = _store.GetValue <string>(uniqueKey);

            //Save modified version
            _store.TrySetValue(uniqueKey, "modifiedState", value.Hash).Should().BeTrue();
            _store.TrySetValue(uniqueKey, "modifiedStateAgain", value.Hash).Should().BeFalse();
            //Assert
            HashedValue <string> modifiedvalue = _store.GetValue <string>(uniqueKey);

            modifiedvalue.Value.Should().Be("modifiedState");
        }