Example #1
0
 public when_setting_item_in_cache_and_operation_fails()
 {
     Given(() => item_is_handled_and_key_generated("simplekey"));
     Given(() => value_serialized_to("source_value", "formatted_value"));
     Given(() => item_is_not_stored_in_cache("simplekey", "formatted_value", ttl));
     When(() => result = OnStoreItem(GetStoreMode(), item => item.ValueOf("source_value"), ttl));
 }
Example #2
0
        private void Store(StoreCommand cmd, List <MailMessage> mails)
        {
            using (var ctx = new MSGorillaMailEntities())
            {
                foreach (var mail in mails)
                {
                    var curMail = ctx.MailMessages.Find(mail.ID);
                    if (cmd.Action == StoreCommand.ActionType.AddFlag)
                    {
                        AddFlags(curMail, cmd.Flags);
                    }
                    else if (cmd.Action == StoreCommand.ActionType.RemoveFlag)
                    {
                        RemoveFlags(curMail, cmd.Flags);
                    }
                    else
                    {
                        SetFlags(curMail, cmd.Flags);
                    }

                    if (cmd.IsSilent == false)
                    {
                        FetchResponse response = new FetchResponse(curMail.SequenceNumber);
                        response.Items.Add(new FetchDataItem(FetchDataItemType.Flags, CreateFlaggedString(curMail)));
                        this.Session.AppendResponse(response);
                    }
                }

                ctx.SaveChanges();
            }
        }
Example #3
0
        public async Task StoreCommand_ExecuteAsync_CallsHostProvider()
        {
            const string testUserName  = "******";
            const string testPassword  = "******";
            var          stdin         = $"username={testUserName}\npassword={testPassword}\n\n";
            var          expectedInput = new InputArguments(new Dictionary <string, string>
            {
                ["username"] = testUserName,
                ["password"] = testPassword
            });

            var providerMock = new Mock <IHostProvider>();

            providerMock.Setup(x => x.StoreCredentialAsync(It.IsAny <InputArguments>()))
            .Returns(Task.CompletedTask);
            var providerRegistry = new TestHostProviderRegistry {
                Provider = providerMock.Object
            };
            var context = new TestCommandContext
            {
                Streams = { In = stdin }
            };

            string[] cmdArgs = { "store" };
            var      command = new StoreCommand(providerRegistry);

            await command.ExecuteAsync(context, cmdArgs);

            providerMock.Verify(
                x => x.StoreCredentialAsync(It.Is <InputArguments>(y => AreInputArgumentsEquivalent(expectedInput, y))),
                Times.Once);
        }
 internal StoreOperationBase(StoreCommand mode, string key, CacheItem value, uint expires, ulong cas) : base(key)
 {
     this.command = mode;
     this.value   = value;
     this.expires = expires;
     this.cas     = cas;
 }
Example #5
0
 public when_setting_item_in_cache_and_operation_succeeds()
 {
     Given(() => item_is_handled_and_key_generated("simplekey"));
     Given(() => value_serialized_to("source_value", "formatted_value"));
     Given(() => item_is_stored_in_cache_sucessfully("simplekey", "formatted_value", TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
     When(() => result = OnStoreItem(GetStoreMode(), item => item.ValueOf("source_value"), TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
 }
Example #6
0
      public async Task StoreCommand_ExecuteAsync_CallsHostProvider()
      {
          const string testUserName  = "******";
          const string testPassword  = "******";  // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")]
          var          stdin         = $"protocol=http\nhost=example.com\nusername={testUserName}\npassword={testPassword}\n\n";
          var          expectedInput = new InputArguments(new Dictionary <string, string>
            {
                ["protocol"] = "http",
                ["host"]     = "example.com",
                ["username"] = testUserName,
                ["password"] = testPassword
            });

          var providerMock = new Mock <IHostProvider>();

          providerMock.Setup(x => x.StoreCredentialAsync(It.IsAny <InputArguments>()))
          .Returns(Task.CompletedTask);
          var providerRegistry = new TestHostProviderRegistry {
              Provider = providerMock.Object
          };
          var context = new TestCommandContext
          {
              Streams = { In = stdin }
          };

          var command = new StoreCommand(context, providerRegistry);

          await command.ExecuteAsync();

          providerMock.Verify(
              x => x.StoreCredentialAsync(It.Is <InputArguments>(y => AreInputArgumentsEquivalent(expectedInput, y))),
              Times.Once);
      }
Example #7
0
        public void ItAddsProjectToMsbuildInvocation(string optionName)
        {
            var msbuildPath = "<msbuildpath>";

            string[] args = new string[] { optionName, "<project>" };
            StoreCommand.FromArgs(args, msbuildPath)
            .GetArgumentsToMSBuild().Should().Contain($"{ExpectedPrefix}");
        }
 internal StoreOperationBase(StoreCommand mode, string key, CacheItem value, uint expires, ulong cas)
     : base(key)
 {
     this.command = mode;
     this.value = value;
     this.expires = expires;
     this.cas = cas;
 }
Example #9
0
 public virtual void ProcessStoreCommand(StoreCommand cmd)
 {
     this.Session.AppendResponse(
         new ServerStatusResponse(cmd.Tag,
                                  ServerStatusResponseType.NO,
                                  "STORE State Error")
         );
 }
Example #10
0
        public void ItAddsProjectToMsbuildInvocation(string optionName)
        {
            var msbuildPath = "<msbuildpath>";

            string[] args = new string[] { optionName, "<project>" };
            StoreCommand.FromArgs(args, msbuildPath)
            .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}");
        }
Example #11
0
		internal StoreOperation(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
			: base(pool, key)
		{
			this.mode = mode;
			this.value = value;
			this.casValue = casValue;

			this.expires = GetExpiration(validFor, expiresAt);
		}
Example #12
0
        internal StoreOperation(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
            : base(pool, key)
        {
            this.mode     = mode;
            this.value    = value;
            this.casValue = casValue;

            expires = GetExpiration(validFor, expiresAt);
        }
        public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
        {
            args = ArgsPrefix.Concat(args).ToArray();
            expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");

            var msbuildPath = "<msbuildpath>";

            StoreCommand.FromArgs(args, msbuildPath)
            .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
        }
Example #14
0
        public void ItAddsOutputPathToMsBuildInvocation(string optionName)
        {
            string path = Path.Combine("some", "path");
            var    args = ArgsPrefix.Concat(new string[] { optionName, path }).ToArray();

            var msbuildPath = "<msbuildpath>";

            StoreCommand.FromArgs(args, msbuildPath)
            .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix} -property:ComposeDir={Path.GetFullPath(path)}");
        }
Example #15
0
        private void OnHandleStore(StoreCommand storeCommand)
        {
            var item           = storeCommand.Item;
            var commandContext = new CommandContext(storeCommand, item);
            var key            = ProcessItemAndBuildKey(commandContext);
            var value          = _formattingServices.Serialize(item.Data, commandContext);
            var succeded       = _memcachedClient.Store(storeCommand.StoreMode, key, value, storeCommand.TimeToLive);

            storeCommand.SetResult(succeded);
        }
Example #16
0
        private void OnHandleCheckAndSet(StoreCommand command)
        {
            var item           = command.Item;
            var commandContext = new CommandContext(command, item);
            var key            = ProcessItemAndBuildKey(commandContext);
            var value          = _formattingServices.Serialize(item.Data, commandContext);
            var casResult      = _memcachedClient.Cas(key, value, command.UniqueID, command.TimeToLive);

            command.SetResult(casResult);
        }
Example #17
0
        public override void ProcessStoreCommand(StoreCommand cmd)
        {
            List <MailMessage> mails = GetMailMessagesFromCmd(cmd);

            Store(cmd, mails);

            this.Session.AppendResponse(
                new ServerStatusResponse(cmd.Tag,
                                         ServerStatusResponseType.OK,
                                         "STORE completed")
                );
        }
Example #18
0
 public when_setting_item_with_check_and_item_was_already_updated_by_someone_else()
 {
     Given(() => item_is_handled_and_key_generated("simplekey"));
     Given(() => value_serialized_to("source_value", "formatted_value"));
     Given(() => item_was_already_updated_by_someone_else(
               "simplekey",
               "formatted_value",
               12,
               TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
     When(() => result = runtime.CheckAndSet(
              item => item.ValueOf("source_value"),
              12,
              TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
 }
Example #19
0
        private static bool Store(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
        {
            if (value == null)
            {
                return(false);
            }

            using (StoreOperation s = new StoreOperation(pool, mode, key, value, casValue, validFor, expiresAt))
            {
                s.Execute();

                return(s.Success);
            }
        }
Example #20
0
 public when_setting_item_with_check_and_operation_fails()
 {
     Given(() => item_is_handled_and_key_generated("simplekey"));
     Given(() => value_serialized_to("source_value", "formatted_value"));
     Given(() => item_is_checked_but_is_not_stored_successfully(
               "simplekey",
               "formatted_value",
               12,
               TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
     When(() => result = runtime.CheckAndSet(
              item => item.ValueOf("source_value"),
              12,
              TimeToLive.CreateValidFor(TimeSpan.FromMinutes(2))));
 }
Example #21
0
        private static bool Store(ServerPool pool, StoreCommand mode, string key, byte[] value, ulong casValue, int offset, int length, TimeSpan validFor, DateTime expiresAt)
        {
            if (value == null)
            {
                return(false);
            }

            using (StoreOperation s = new StoreOperation(pool, mode, key, new ArraySegment <byte>(value, offset, length), casValue, validFor, expiresAt))
            {
                s.Execute();

                return(s.Success);
            }
        }
Example #22
0
        public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
        {
            CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () =>
            {
                args = ArgsPrefix.Concat(args).ToArray();
                expectedAdditionalArgs =
                    (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}")
                    .Replace("<cwd>", WorkingDirectory);

                var msbuildPath = "<msbuildpath>";
                StoreCommand.FromArgs(args, msbuildPath)
                .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
            });
        }
Example #23
0
        public void StoreCommand_CanExecuteAsync(string argString, bool expected)
        {
            var command = new StoreCommand(Mock.Of <IHostProviderRegistry>());

            bool result = command.CanExecute(argString?.Split(null));

            if (expected)
            {
                Assert.True(result);
            }
            else
            {
                Assert.False(result);
            }
        }
Example #24
0
        private void ExecuteStoreCommand(Bot bot, StoreCommand storeCommand)
        {
            int a, b;

            switch (storeCommand)
            {
            case StoreCommand.Store:
                b = SystemVariables.NormaliseAddress(IntStack.Pop());
                a = IntStack.Pop();
                if (SystemVariables.IsAddressWritable(b))
                {
                    bot.Memory[b] = a;
                }
                break;
            }
        }
Example #25
0
        public void Execute()
        {
            if (!CanExecute)
            {
                throw new InvalidOperationException("Cannot execute in the current state");
            }

            if (CurrentLine != null)
            {
                Command cmd;
                switch (CurrentLine.Instruction)
                {
                case MoveInstruction _:
                    cmd = new MoveCommand(this);
                    break;

                case ArithmeticInstruction _:
                    cmd = new ArithmeticCommand(this);
                    break;

                case BranchInstruction _:
                    cmd = new BranchCommand(this);
                    break;

                case HaltInstruction _:
                    cmd = new HaltCommand(this);
                    break;

                case StoreInstruction _:
                    cmd = new StoreCommand(this);
                    break;

                case LoadInstruction _:
                    cmd = new LoadCommand(this);
                    break;

                case NoOperation _:
                    cmd = new NoCommand(this);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                cmd.Execute();
            }
        }
        public void LogStore(StoreCommand cmd, bool success)
        {
            pcStore_PerSec.Increment();
            pcStore_Total.Increment();

            switch (cmd)
            {
                case StoreCommand.Add:
                    pcAdd_PerSec.Increment();
                    pcAdd_Total.Increment();
                    break;

                case StoreCommand.Append:
                    pcAppend_PerSec.Increment();
                    pcAppend_Total.Increment();
                    break;

                case StoreCommand.CheckAndSet:
                    pcCAS_PerSec.Increment();
                    pcCAS_Total.Increment();
                    break;

                case StoreCommand.Prepend:
                    pcPrepend_PerSec.Increment();
                    pcPrepend_Total.Increment();
                    break;

                case StoreCommand.Replace:
                    pcReplace_PerSec.Increment();
                    pcReplace_Total.Increment();
                    break;

                case StoreCommand.Set:
                    pcSet_PerSec.Increment();
                    pcSet_Total.Increment();
                    break;
            }

            if (success)
            {
                pcStore_Success.Increment();

                switch (cmd)
                {
                    case StoreCommand.Add:
                        pcAdd_Success.Increment();
                        break;

                    case StoreCommand.Append:
                        pcAppend_Success.Increment();
                        break;

                    case StoreCommand.CheckAndSet:
                        pcCAS_Success.Increment();
                        break;

                    case StoreCommand.Prepend:
                        pcPrepend_Success.Increment();
                        break;

                    case StoreCommand.Replace:
                        pcReplace_Success.Increment();
                        break;

                    case StoreCommand.Set:
                        pcSet_Success.Increment();
                        break;
                }
            }

            if (!this.global)
                GlobalInstance.LogStore(cmd, success);
        }
 void IPerformanceCounters.LogStore(StoreCommand cmd, bool success)
 {
 }