Ejemplo n.º 1
0
        private void Seed()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                for (int i = 0; i < 5; i++)
                {
                    var account1 = new Account
                    {
                        Email = new Email
                        {
                            Value = $"Account{i}@email.com",
                        },
                        Username = new Username
                        {
                            Value = $"Account{i}Username"
                        },
                        Password = new Password
                        {
                            Value = "Password"
                        }
                    };

                    context.Add(account1);
                    context.SaveChanges();
                }
            }
        }
        public void CreatePost_PassedValidPost_PostIsCreated()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create a post service
                var postService = new PostService(context);

                // Create a post (1 is account in seeded database)
                var post = new Post
                {
                    AccountId   = 1,
                    Description = "Post Description",
                    MediaUrl    = "UrlToMedia"
                };

                /// Act
                // Save post
                postService.CreatePost(post, 1);

                /// Assert
                // Ensure post was created
                Assert.NotNull(context.Posts.FirstOrDefault(p => p.AccountId == 1));
            }
        }
        public void GetPosts_ViewerIsTheAccount_ReturnsPosts()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create a post service
                var postService = new PostService(context);

                //  Create a post for account 1
                var post = new Post
                {
                    AccountId   = 1,
                    Description = "Post Description",
                    MediaUrl    = "UrlToMedia"
                };

                // Save post
                postService.CreatePost(post, 1);

                /// Act
                // GetPosts where viewerId and accountId are 1
                /// Act
                // View account 1's posts as account 2
                var posts = postService.GetPosts(1, 1);

                /// Assert
                // The posts are returned
                Assert.True(posts.Count > 0);
            }
        }
Ejemplo n.º 4
0
        public void GetRequests_GivenUserWithThreeRequests_ReturnsAllRequests()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Get requestService
                var requestService = new RequestService(context);

                // Create Request to account 2 from 1
                var request = new RequestDTO {
                    SenderId = 1, RecepientId = 2
                };
                requestService.SaveRequest(request);

                // Create another Request to account 2 from 3
                request = new RequestDTO {
                    SenderId = 3, RecepientId = 2
                };
                requestService.SaveRequest(request);

                /// Act
                // Get requests for account one
                var requestsInDB = requestService.GetRequests(1);

                /// Assert
                // Ensure the total requests is one
                Assert.True(requestsInDB.Count == 1);
            }
        }
Ejemplo n.º 5
0
        public void RespondToRequest_Accept_AccountsAreAddedToEachothersCircle()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Get requestService
                var requestService = new RequestService(context);

                // Create Request to account 2 from 1
                var request = new RequestDTO {
                    SenderId = 1, RecepientId = 2
                };
                requestService.SaveRequest(request);

                /// Act
                // Respond to the request
                requestService.RespondToRequest(1, "Accepted");

                /// Assert
                // Get the Circle Account 1 and 2
                var accountOneCircle = context.Circles.Include(c => c.Members).FirstOrDefault(c => c.AccountId == 1);
                var accountTwoCircle = context.Circles.Include(c => c.Members).FirstOrDefault(c => c.AccountId == 2);

                // Ensure that account1 circle has account 2 as member
                Assert.Contains(accountOneCircle.Members, c => c.AccountId == 2);

                // Ensure that account2 circle has account 1 as member
                Assert.Contains(accountTwoCircle.Members, c => c.AccountId == 1);
            }
        }
Ejemplo n.º 6
0
        public void CreateAccount_UsernameAlreadyInUse_ThrowsException()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Get Accounts service
                var AccountService = new AccountService(context);

                // Create a new account DTO
                var account = new AccountDTO
                {
                    Username  = "******",
                    Password  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "A1First",
                    LastName  = "A1Last"
                };

                AccountService.CreateAccount(account);

                // Change values in dto other than the username
                account.Email     = "*****@*****.**";
                account.FirstName = "first";
                account.LastName  = "last";

                /// Act
                // Create another account with same username
                var exception = Record.Exception(() => AccountService.CreateAccount(account));

                /// Assert
                // Ensure exception was thrown
                Assert.NotNull(exception);
            }
        }
Ejemplo n.º 7
0
        public void SaveRequest_ValidRequestDTO_RequestIsCreated()
        {
            // Create a new in memory context
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create controller with the new context
                var requestService = new RequestService(context);

                // Create a request DTO for accounts already in db
                var request = new RequestDTO
                {
                    SenderId    = 1,
                    RecepientId = 2,
                };

                /// Act
                requestService.SaveRequest(request);

                /// Assert
                // Get a request from db with values in dto
                var dbRequest = context.Requests.FirstOrDefault(r => r.SenderId == request.SenderId && r.RecepientId == r.RecepientId);

                // Ensure it is not null
                Assert.NotNull(dbRequest);
            }
        }
        public void GetPosts_ViewerIsInAccountCircle_ReturnsPosts()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create a post service
                var postService = new PostService(context);

                // Create a post (1 is account in seeded database)
                var post = new Post
                {
                    AccountId   = 1,
                    Description = "Post Description",
                    MediaUrl    = "UrlToMedia"
                };

                // Save post
                postService.CreatePost(post, 1);

                /// Act
                // View account 1's posts as account 2
                var posts = postService.GetPosts(2, 1);

                /// Assert
                // Make sure correct amount of posts are returned
                Assert.True(posts.Count > 0);
            }
        }
Ejemplo n.º 9
0
        public void CreateAccount_NewUsername_AccountIsSaved()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Get Accounts service
                var AccountService = new AccountService(context);

                // Create a new account DTO
                var account = new AccountDTO
                {
                    Username  = "******",
                    Password  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "A1First",
                    LastName  = "A1Last"
                };

                /// Act
                // Create the account
                AccountService.CreateAccount(account);

                /// Assert
                // Ensure the account was created in the db
                var SavedAccount = context.Accounts.FirstOrDefault(a => a.AccountId == 1);

                Assert.NotNull(SavedAccount);
            }
        }
Ejemplo n.º 10
0
        private void Seed()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                // Create 3 accounts
                for (int i = 0; i < 3; i++)
                {
                    var account1 = new Account
                    {
                        Email = new Email
                        {
                            Value = $"Account{i}@email.com",
                        },
                        Username = new Username
                        {
                            Value = $"Account{i}Username"
                        },
                        Password = new Password
                        {
                            Value = "Password"
                        }
                    };

                    context.Add(account1);
                }
                context.SaveChanges();


                // Make accounts 1 and 2 members of circle
                var CircleMember = new CircleMember()
                {
                    CircleId = 1, AccountId = 2
                };
                var CircleMember2 = new CircleMember()
                {
                    CircleId = 2, AccountId = 2
                };
                context.Add(CircleMember2);
                context.Add(CircleMember);

                context.SaveChanges();

                for (int i = 0; i < 3; i++)
                {
                    var post = new Post()
                    {
                        AccountId   = 3,
                        Description = $"Post number {i} ",
                        MediaUrl    = $"url{i}",
                        Username    = $"Account3Username"
                    };
                    context.Add(post);
                    context.SaveChanges();
                }
            }
        }
 private void Seed()
 {
     using (var context = new InnerCircleDataContext(ContextOptions))
     {
         context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
     }
 }
Ejemplo n.º 12
0
        private void JoinCircle(long id1, long id2, InnerCircleDataContext context)
        {
            var requestService = new RequestService(context);

            requestService.SaveRequest(new RequestDTO {
                RecepientId = id1, SenderId = id2, RecepientUsername = "", SenderUsername = ""
            });
            var requests = requestService.GetRequests(id1);

            requestService.RespondToRequest(requests.FirstOrDefault().RequestId, "Accepted");
        }
Ejemplo n.º 13
0
        public void GetAccount_AccountExistsAndIsNotInCircle_ReturnsDtoWithCorrectValues()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create accounts and join circle
                CreateAccounts(2, context);

                // Create AccountService
                var AccountService = new AccountService(context);

                /// Act
                // Try to view account 2 with account 1
                var accountViewDTO = AccountService.GetAccount(1, 2);

                Assert.True(accountViewDTO.Requestable);
            }
        }
        public void GetPosts_ViewerIsNotInCircle_ReturnsEmptyList()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create a post service
                var postService = new PostService(context);

                // From the seed Account 3 has posts and is not in Account 1's circle

                /// Act
                // Have account 1 try to view account 3 posts
                var posts = postService.GetPosts(1, 3);

                /// Assert
                // Ensure post was created
                Assert.True(posts.Count == 0);
            }
        }
Ejemplo n.º 15
0
        public void CreateMessage_ValidMessageDTO_SaveMessage()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                var MessageService = new MessageService(context);

                // Create a new message DTO
                var message = new MessageDTO
                {
                    RecepientId = 2,
                    SenderId    = 1,
                    Message     = "Hello"
                };
                MessageService.CreateMessage(message);

                var SavedMessage = context.Messages.FirstOrDefault(a => a.MessageId == 1);

                Assert.NotNull(SavedMessage);
            }
        }
        public void ParseDataURL_GivenValidMp4Url_ReturnsDictionary()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Get post service
                var postService = new PostService(context);
                // Get media url to convert
                var mediaUrl = "data:video/mp4;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/4U+eRXhpZgAATU0AKgAAAAgADwALAAIAAAAmAAAIzgEPAAIAAAASAAAI9AEQAAIAAAAMAAAJBgESAAMA";
                /// Act
                // Convert the media url
                var result    = postService.ParseDataURL(mediaUrl);
                var exception = Record.Exception(() => Convert.FromBase64String(result["data"]));

                /// Assert
                // Ensure no exception is thrown when converting the string and the image type is correct
                Assert.Null(exception);
                Assert.True(".mp4" == result["extension"]);
            }
        }
Ejemplo n.º 17
0
 private void CreateAccounts(int count, InnerCircleDataContext context)
 {
     for (int i = 0; i < 5; i++)
     {
         var account1 = new Account
         {
             Email = new Email
             {
                 Value = $"Account{i}@email.com",
             },
             Username = new Username
             {
                 Value = $"Account{i}Username"
             },
             Password = new Password
             {
                 Value = "Password"
             }
         };
         context.Add(account1);
         context.SaveChanges();
     }
 }
Ejemplo n.º 18
0
        public void GetMessages_TwoAccountId_ReturnListOfMessages()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                var MessageService = new MessageService(context);

                // Create a new message DTO
                var message = new MessageDTO
                {
                    RecepientId = 2,
                    SenderId    = 1,
                    Message     = "Hello"
                };
                MessageService.CreateMessage(message);

                message = new MessageDTO
                {
                    RecepientId = 1,
                    SenderId    = 2,
                    Message     = "Hello2"
                };
                MessageService.CreateMessage(message);

                message = new MessageDTO
                {
                    RecepientId = 1,
                    SenderId    = 3,
                    Message     = "Hello"
                };
                MessageService.CreateMessage(message);

                var Test = MessageService.GetMessages(1, 2);

                Assert.All <Message>(Test, m => Assert.True(m.SenderId == 1 || m.SenderId == 2 &&
                                                            (m.RecepientId == 1 || m.RecepientId == 2)));
            }
        }
Ejemplo n.º 19
0
        public void GetAccount_AccountExistsAndHasPendingRequest_ReturnsDtoWithCorrectValues()
        {
            using (var context = new InnerCircleDataContext(ContextOptions))
            {
                /// Arrange
                // Create accounts and join circle
                CreateAccounts(2, context);

                // Create a request for the accounts
                var RequestService = new RequestService(context);
                RequestService.SaveRequest(new RequestDTO {
                    RecepientId = 1, SenderId = 2
                });

                // Create AccountService
                var AccountService = new AccountService(context);

                /// Act
                // Try to view account 2 with account 1
                var accountViewDTO = AccountService.GetAccount(1, 2);

                Assert.False(accountViewDTO.Requestable);
            }
        }
 public LoginController(InnerCircleDataContext context, IConfiguration config, Authorization authManager)
 {
     _context     = context;
     _authManager = authManager;
 }
 public MessageService(InnerCircleDataContext Context)
 {
     _context = Context;
 }
Ejemplo n.º 22
0
 public AccountsController(InnerCircleDataContext context, Authorization authManager)
 {
     _context       = context;
     _authManager   = authManager;
     AccountService = new AccountService(context);
 }
 public PostService(InnerCircleDataContext Context)
 {
     _context = Context;
 }
Ejemplo n.º 24
0
 public AccountService(InnerCircleDataContext context)
 {
     _context = context;
 }
Ejemplo n.º 25
0
 public RequestService(InnerCircleDataContext context)
 {
     _context = context;
 }
Ejemplo n.º 26
0
 public MessageController(InnerCircleDataContext context)
 {
     _context       = context;
     MessageService = new MessageService(context);
 }
 public PostController(InnerCircleDataContext context)
 {
     _context    = context;
     PostService = new PostService(context);
 }
 public Authorization(InnerCircleDataContext context, IConfiguration config)
 {
     _context = context;
     _config  = config;
 }
 public RequestController(InnerCircleDataContext context)
 {
     _context       = context;
     RequestService = new RequestService(context);
 }