public void Persist(Daffodil daffodil)
        {
            #if DEBUG
            Assert.Fail(()=>(!String.IsNullOrWhiteSpace(_serviceUrl)), "You are a big dummy!");
            #endif

            this.CreateDomainIfNecessary("daffodil");

            var client = this.GetClient();
            var attributes = new List<ReplaceableAttribute>
                                 {
                                     new ReplaceableAttribute
                                         {
                                             Name = "Id",
                                             Replace = true,
                                             Value = daffodil.Id,
                                         },
                                     new ReplaceableAttribute
                                         {
                                             Name = "Data",
                                             Replace = true,
                                             Value = daffodil.Data,
                                         }
                                 };

            var request = new PutAttributesRequest
                              {
                                  DomainName = "daffodil",
                                  Attribute = attributes,
                                  ItemName = daffodil.Id
                              };
            client.PutAttributes(request);
        }
 public void Persist_persists_without_error()
 {
     var config = this.AwsConfig;
     var provider = new SimpleDbProvider(config);
     var daffodil = new Daffodil {Id = "foo2", Data = "bar2"};
     provider.Persist(daffodil);
 }
        public void Read_successfully_reads()
        {
            // Arrange
            var config = this.AwsConfig;
            var provider = new SimpleDbProvider(config);
            var daffodil = new Daffodil { Id = "foo", Data = "bar" };
            provider.Persist(daffodil);

            // Act
            var daffodilFromDb = provider.Read("daffodil", "foo");

            // Assert
            Assert.That(daffodilFromDb.Data, Is.EqualTo("bar"));
        }
        public void ReadDaffodils_successfully_reads()
        {
            // Arrange
            var config = this.AwsConfig;
            var provider = new SimpleDbProvider(config);
            var daffodil = new Daffodil { Id = "foo", Data = "bar" };
            provider.Persist(daffodil);

            // Act
            var daffodilsFromDb = provider.ReadDaffodils();

            // Assert
            Assert.That(daffodilsFromDb.Count, Is.GreaterThanOrEqualTo(1));
        }
        public ActionResult Data(string id, string data)
        {
            var config = this.AwsConfig;

            var queueProvider = new QueueProvider(config);
            var daffodil = new Daffodil
                               {
                                   Id = id,
                                   Data = data,
                               };

            queueProvider.SendMessage("daffodils", daffodil);
            return Content("success");
        }
        public virtual List<Daffodil> ReadDaffodils()
        {
            var daffodils = new List<Daffodil>();

            var client = this.GetClient();
            var request = new SelectRequest
            {
                SelectExpression = "SELECT * FROM daffodil",
            };

            var response = client.Select(request);
            var items = response.SelectResult.Item;
            foreach(var item in items)
            {
                var idFromDb = item.Attribute.First(x => x.Name == "Id").Value;
                var dataFromDb = item.Attribute.First(x => x.Name == "Data").Value;

                var daffodil = new Daffodil
                {
                    Id = idFromDb,
                    Data = dataFromDb,
                };

                daffodils.Add(daffodil);
            }

            return daffodils;
        }
        public virtual Daffodil Read(string domain, string id)
        {
            var client = this.GetClient();
            var request = new GetAttributesRequest
                              {
                                  ItemName = id,
                                  DomainName = domain,
                              };

            var response = client.GetAttributes(request);
            var attributes = response.GetAttributesResult.Attribute;
            var idFromDb = attributes.First(x => x.Name == "Id").Value;
            var dataFromDb = attributes.First(x => x.Name == "Data").Value;

            var daffodil = new Daffodil
                               {
                                   Id = idFromDb,
                                   Data = dataFromDb,
                               };

            return daffodil;
        }
        public virtual void SendMessage(string queueName, Daffodil daffodil)
        {
            #if DEBUG
            Assert.Fail(() => (!String.IsNullOrWhiteSpace(_baseUrl)), "Hey!  Your _baseUrl is null or blank, dummy!");

            #endif

            this.CreateQueueIfNecessary(queueName);

            var serializedData = daffodil.SerializeToJson<Daffodil>();

            var client = this.GetClient();
            var request = new SendMessageRequest
                              {
                                  MessageBody = serializedData,
                                  QueueUrl = this.CalculateQueueUrl(_baseUrl, queueName),
                              };

            var response = client.SendMessage(request);
        }