コード例 #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));
 }
コード例 #2
0
ファイル: SelectedState.cs プロジェクト: fudanyi/MSGorilla
        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();
            }
        }
コード例 #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);
        }
コード例 #4
0
 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;
 }
コード例 #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))));
 }
コード例 #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);
      }
コード例 #7
0
        public void ItAddsProjectToMsbuildInvocation(string optionName)
        {
            var msbuildPath = "<msbuildpath>";

            string[] args = new string[] { optionName, "<project>" };
            StoreCommand.FromArgs(args, msbuildPath)
            .GetArgumentsToMSBuild().Should().Contain($"{ExpectedPrefix}");
        }
コード例 #8
0
 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;
 }
コード例 #9
0
ファイル: BaseState.cs プロジェクト: fudanyi/MSGorilla
 public virtual void ProcessStoreCommand(StoreCommand cmd)
 {
     this.Session.AppendResponse(
         new ServerStatusResponse(cmd.Tag,
                                  ServerStatusResponseType.NO,
                                  "STORE State Error")
         );
 }
コード例 #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}");
        }
コード例 #11
0
ファイル: StoreOperation.cs プロジェクト: xxjeng/nuxleus
		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);
		}
コード例 #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);
        }
コード例 #13
0
        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}");
        }
コード例 #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)}");
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #17
0
ファイル: SelectedState.cs プロジェクト: fudanyi/MSGorilla
        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")
                );
        }
コード例 #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))));
 }
コード例 #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);
            }
        }
コード例 #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))));
 }
コード例 #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);
            }
        }
コード例 #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}");
            });
        }
コード例 #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);
            }
        }
コード例 #24
0
ファイル: DNAEngine.cs プロジェクト: trichards57/ALife
        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;
            }
        }
コード例 #25
0
ファイル: PlottyMachine.cs プロジェクト: attackgithub/Plotty
        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)
 {
 }