public void PostChannelTest()
        {
            bool isItemAdded = false;
            var repository = Mock.Create<IRepository>();
            List<Message> messages = new List<Message>();
            messages.Add(new Message(){ Title="some", Content="some", Type = MessageTypes.Text});
            var value = new Channel()
            {
                Name = "someChannel",
                Password = "******",
                CreatedDateTime = DateTime.Now,
                NumberOfMessages = 1,
                Messages = messages

            };

            Mock.Arrange(() => repository.Create(Arg.IsAny<Channel>()))
                 .DoInstead(() => isItemAdded = true)
                 .Returns(value);

            var controller = new ChannelController(repository);
            SetupChannelControllerPost(controller);
            controller.Post(value);
            Assert.IsTrue(isItemAdded);
        }
        public void GetChannelTest()
        {
            var repository = Mock.Create<IRepository>();
            var value = new Channel()
            {
                Id = "1235123123",
                Name = "someChannel",
                Password = "******",
                CreatedDateTime = DateTime.Now
            };

            Mock.Arrange<Channel>(
                () => repository.Find<Channel>(c => c.Id == value.Id, null))
                .IgnoreArguments()
                .Returns(value)
                .MustBeCalled();

            var target = new ChannelController(repository);
            var result = target.Get(value.Id);
            Assert.AreEqual(result.Id, value.Id);
        }
Ejemplo n.º 3
0
 public static void AddSafeName(this List<Channel> l, Channel value)
 {
     if (l.Find(c => c.Name == value.Name) == null)
         l.Add(value);
 }
Ejemplo n.º 4
0
 public static SafeModeResult SaveUser(this SessionState _sessionState, Channel value)
 {
     var result = _sessionState.db.GetCollection<User>("User").Save(value, SafeMode.True);
     if (result.Ok)
         AppCache.ChannelList.AddSafeName(value);
     return result;
 }
Ejemplo n.º 5
0
        public static Channel GetChannel(this SessionState _sessionState, string name, string password, PubnubAPI pubnub)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
                return null;
            Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.Password == password).FirstOrDefault();
            if (result == null)
            {
                //try to get channel from mongodb
                result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault();
                if (result == null)
                {
                    //save new channel
                    result = new Channel();
                    result.Name = name;
                    result.Password = password;
                    result.CreatedDateTime = DateTime.Now;
                    _sessionState.SaveChannel(result);
                    //add channel in cache
                    AppCache.ChannelList.AddSafeName(result);
                    if (pubnub != null)
                    {
                        List<object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name);
                    }
                }
                else if(result.Password != password)
                    result = null;

            }
            return result;
        }
Ejemplo n.º 6
0
 public static Channel GetChannel(this SessionState _sessionState, string name)
 {
     if (string.IsNullOrEmpty(name))
         return null;
     Channel result = AppCache.ChannelList.Where(c => c.Name == name).FirstOrDefault();
     if (result == null)
     {
         result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();
         if (result == null)
             result = new Channel();
         AppCache.ChannelList.AddSafeName(result);
     }
     return result;
 }
Ejemplo n.º 7
0
 public static void GetChanMessages(this SessionState _sessionState, Channel chan, int numberOfMessages)
 {
     if (AppCache.MessageList.Where(m => m.ChannelId == chan.Id).OrderBy(m => m.CreatedDateTime).Take(numberOfMessages).ToList().Count == 0)
     {
         _sessionState.GetMessages().Where(m => m.ChannelId == chan.Id).OrderBy(m => m.CreatedDateTime).Take(numberOfMessages).ToList().ForEach(m =>
         {
             m.Status = "add";
             //if (m.Type == MessageTypes.File)
             //{
             //    _sessionState.AuthClient();
             //    var url = _sessionState.DropboxClient.GetMediaLinkAsync(m.Content).Result.Url;
             //    m.Content = url;
             //}
             AppCache.MessageList.AddSafeName(m);
         });
     }
 }
        private void uploadToCloud(string filename, string uploadFileName, Stream fileStream, Message msg, Channel chan, string file)
        {
            if (filename.EndsWith("png") || filename.EndsWith("jpeg") || filename.EndsWith("jpg") || filename.EndsWith("gif") || filename.EndsWith("bmp"))
            {
                try
                {
                    msg.Type = MessageTypes.Image;
                    var configuration = new AccountConfiguration("saykor", "277334748579534", "mUjzZ-X3jOuNKGswrAjocB-D-Rc");

                    var uploader = new Uploader(configuration);
                    string publicId = Path.GetFileNameWithoutExtension(filename);
                    var uploadResult = uploader.Upload(new UploadInformation(filename, fileStream)
                    {
                        PublicId = publicId,
                        Format = filename.Substring(filename.Length - 3),
                    });
                    //msg.Content = uploadResult.Url;
                    msg.Content = filename;
                }
                catch (Exception ex)
                {
                    //context.Response.Write("{ 'success': " + ex.Message + " }");
                    return;
                }
            }
            else
            {
                //upload to dropbox
                string cloudPath = "/" + chan.Name + "/" + filename;
                _sessionState.AuthClient();
                var result = _sessionState.DropboxClient.UploadFileAsync(new FileResource(file), cloudPath).Result;
                msg.Content = cloudPath;
            }
        }