<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using DotNetBay.Data.FileStorage;
using DotNetBay.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DotNetBay.Core.Test
{
    [TestClass]
    public class FileStorageStoreTests
    {
        #region Create Helpers

        private static Auction CreateAnAuction()
        {
            var myAuction = new Auction()
            {
                Title = "TitleOfTheAuction",
                StartPrice = 50.5,
                StartDateTimeUtc = DateTime.UtcNow.AddDays(10),
            };

            return myAuction;
        }

        private static Member CreateAMember()
        {
            return new Member()
            {
                Name = "GeneratedMember",
                UniqueId = "UniqueId" + Guid.NewGuid()
            };
        }


        #endregion

        [TestMethod]
        public void GivenAnEmptyStore_AddOneAuction_NotEmptyAnymore()
        {
            var myAuction = CreateAnAuction();
            myAuction.Seller = CreateAMember();

            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
            }

            Assert.IsNotNull(auctionFromStore);
        }

        [TestMethod]
        public void GivenEmptyStore_AddAuctionWithSeller_AuctionAndMemberAreStoreIndividually()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            myAuction.Seller = myMember;

            Member memberForStore = null;
            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
                memberForStore = testStore.GetMembers().FirstOrDefault();
            }

            Assert.IsNotNull(auctionFromStore, "auctionFromStore != null");
            Assert.IsNotNull(auctionFromStore.Seller, "auctionFromStore.Seller != null");

            Assert.IsNotNull(memberForStore, "memberForStore != null");
            Assert.IsNotNull(memberForStore.Auctions, "memberForStore.Auctions != null");
            Assert.AreEqual(1, memberForStore.Auctions.Count, "There should be exact one euction for this member");
        }

        [TestMethod]
        public void GivenAnEmptyStore_AddAMemberWithAuctions_MemberAndAuctionsAreStoredIndividually()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            // References
            myAuction.Seller = myMember;
            myMember.Auctions = new List<Auction>(new[] { myAuction });

            Member memberForStore = null;
            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myMember);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                memberForStore = testStore.GetMembers().FirstOrDefault();
                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
            }

            Assert.IsNotNull(memberForStore, "memberForStore != null");
            Assert.IsNotNull(memberForStore.Auctions, "memberForStore.Auctions != null");
            Assert.AreEqual(1, memberForStore.Auctions.Count, "There should be exact one euction for this member");

            Assert.IsNotNull(auctionFromStore, "auctionFromStore != null");
            Assert.IsNotNull(auctionFromStore.Seller, "auctionFromStore.Seller != null");
            Assert.AreEqual(auctionFromStore.Seller.UniqueId, myMember.UniqueId);
        }

        [TestMethod]
        public void GivenAnExistingMember_AddAuctionWithExistingMemberAsSeller_AuctionIsAttachedToMember()
        {
            var myMember = CreateAMember();
            var myAuction = CreateAnAuction();
            myAuction.Seller = myMember;

            IQueryable<Member> allMembersFromStore = null;
            IQueryable<Auction> allAuctionFromStore = null;
            
            using (var tempFile = new TempFile())
            {
                var firstStore = new FileStorageProvider(tempFile.FullPath);
                firstStore.Add(myMember);

                var secondStore = new FileStorageProvider(tempFile.FullPath);
                secondStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);
                allAuctionFromStore = testStore.GetAuctions();
                allMembersFromStore = testStore.GetMembers();
            }

            Assert.AreEqual(1, allAuctionFromStore.Count(), "There should be exact 1 auction");
            Assert.AreEqual(1, allMembersFromStore.Count(), "There should be exact 1 member");

            Assert.IsNotNull(allMembersFromStore, "memberForStore != null");
            Assert.IsNotNull(allMembersFromStore.First().Auctions, "memberForStore.Auctions != null");
            
            Assert.AreEqual(1, allMembersFromStore.First().Auctions.Count(), "There should be a auction attached to the member");
            Assert.AreEqual(myAuction.Id, allMembersFromStore.First().Auctions.First().Id);
        }
    }
}<commit_msg>more tests<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using DotNetBay.Data.FileStorage;
using DotNetBay.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DotNetBay.Core.Test
{
    [TestClass]
    public class FileStorageStoreTests
    {
        #region Create Helpers

        private static Auction CreateAnAuction()
        {
            var myAuction = new Auction()
            {
                Title = "TitleOfTheAuction",
                StartPrice = 50.5,
                StartDateTimeUtc = DateTime.UtcNow.AddDays(10),
            };

            return myAuction;
        }

        private static Member CreateAMember()
        {
            return new Member()
            {
                Name = "GeneratedMember",
                UniqueId = "UniqueId" + Guid.NewGuid()
            };
        }


        #endregion

        [TestMethod]
        public void GivenAnEmptyStore_AddOneAuction_NotEmptyAnymore()
        {
            var myAuction = CreateAnAuction();
            myAuction.Seller = CreateAMember();

            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
            }

            Assert.IsNotNull(auctionFromStore);
        }

        [TestMethod]
        public void GivenEmptyStore_AddAuctionWithSeller_AuctionAndMemberAreStoredIndividually()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            myAuction.Seller = myMember;

            Member memberFromStore = null;
            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
                memberFromStore = testStore.GetMembers().FirstOrDefault();
            }

            Assert.IsNotNull(auctionFromStore, "auctionFromStore != null");
            Assert.IsNotNull(auctionFromStore.Seller, "auctionFromStore.Seller != null");

            Assert.IsNotNull(memberFromStore, "memberForStore != null");
            Assert.IsNotNull(memberFromStore.Auctions, "memberForStore.Auctions != null");
            Assert.AreEqual(1, memberFromStore.Auctions.Count, "There should be exact one euction for this member");

            Assert.AreEqual(myAuction.Title, auctionFromStore.Title, "Auction's title is not the same");
            Assert.AreEqual(myMember.UniqueId, memberFromStore.UniqueId, "Member's uniqueId is not the same");
            Assert.AreEqual(1, memberFromStore.Auctions.Count, "There should be exact one euction for this member");
        }

        [TestMethod]
        public void GivenEmptyStore_AddAMemberWithAuctions_MemberAndAuctionsAreStoredIndividually()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            // References
            myAuction.Seller = myMember;
            myMember.Auctions = new List<Auction>(new[] { myAuction });

            Member memberForStore = null;
            Auction auctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var initStore = new FileStorageProvider(tempFile.FullPath);
                initStore.Add(myMember);

                var testStore = new FileStorageProvider(tempFile.FullPath);

                memberForStore = testStore.GetMembers().FirstOrDefault();
                auctionFromStore = testStore.GetAuctions().FirstOrDefault();
            }

            Assert.IsNotNull(memberForStore, "memberForStore != null");
            Assert.IsNotNull(memberForStore.Auctions, "memberForStore.Auctions != null");
            Assert.AreEqual(1, memberForStore.Auctions.Count, "There should be exact one euction for this member");

            Assert.IsNotNull(auctionFromStore, "auctionFromStore != null");
            Assert.IsNotNull(auctionFromStore.Seller, "auctionFromStore.Seller != null");
            Assert.AreEqual(auctionFromStore.Seller.UniqueId, myMember.UniqueId);
        }

        [TestMethod]
        public void GivenAnExistingMember_AddAuctionWithExistingMemberAsSeller_AuctionIsAttachedToMember()
        {
            var myMember = CreateAMember();
            var myAuction = CreateAnAuction();

            // References
            myAuction.Seller = myMember;

            IQueryable<Member> allMembersFromStore = null;
            IQueryable<Auction> allAuctionFromStore = null;
            
            using (var tempFile = new TempFile())
            {
                var firstStore = new FileStorageProvider(tempFile.FullPath);
                firstStore.Add(myMember);

                var secondStore = new FileStorageProvider(tempFile.FullPath);
                secondStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);
                allAuctionFromStore = testStore.GetAuctions();
                allMembersFromStore = testStore.GetMembers();
            }

            Assert.AreEqual(1, allAuctionFromStore.Count(), "There should be exact 1 auction");
            Assert.AreEqual(1, allMembersFromStore.Count(), "There should be exact 1 member");

            Assert.IsNotNull(allMembersFromStore, "memberForStore != null");
            Assert.IsNotNull(allMembersFromStore.First().Auctions, "memberForStore.Auctions != null");
            
            Assert.AreEqual(1, allMembersFromStore.First().Auctions.Count(), "There should be a auction attached to the member");
            Assert.AreEqual(myAuction.Id, allMembersFromStore.First().Auctions.First().Id);
        }

        [TestMethod]
        [ExpectedException(typeof (ArgumentException))]
        public void GivenAStoreWithMember_AddMemberAgain_ShouldRaiseExecption()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            // References
            myAuction.Seller = myMember;
            myMember.Auctions = new List<Auction>(new[] { myAuction });

            using (var tempFile = new TempFile())
            {
                var firstStore = new FileStorageProvider(tempFile.FullPath);
                firstStore.Add(myMember);

                var testSore = new FileStorageProvider(tempFile.FullPath);
                testSore.Add(myMember);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void GivenAStoreWithAuction_AddAuctionAgain_ShouldRaiseExecption()
        {
            var myAuction = CreateAnAuction();
            var myMember = CreateAMember();

            // References
            myAuction.Seller = myMember;
            myMember.Auctions = new List<Auction>(new[] { myAuction });

            using (var tempFile = new TempFile())
            {
                var firstStore = new FileStorageProvider(tempFile.FullPath);
                firstStore.Add(myAuction);

                var testSore = new FileStorageProvider(tempFile.FullPath);
                testSore.Add(myAuction);
            }
        }

        [TestMethod]
        public void GivenAnEmptyStore_AddAuctionAndMember_ReferencesShouldBeEqual()
        {
            var myMember = CreateAMember();
            var myAuction = CreateAnAuction();

            // References
            myAuction.Seller = myMember;
            myMember.Auctions = new List<Auction>(new[] { myAuction });

            IQueryable<Member> allMembersFromStore = null;
            IQueryable<Auction> allAuctionFromStore = null;

            using (var tempFile = new TempFile())
            {
                var firstStore = new FileStorageProvider(tempFile.FullPath);
                firstStore.Add(myAuction);

                var testStore = new FileStorageProvider(tempFile.FullPath);
                allAuctionFromStore = testStore.GetAuctions();
                allMembersFromStore = testStore.GetMembers();
            }

            Assert.AreEqual(1, allAuctionFromStore.Count(), "There should be exact 1 auction");
            Assert.AreEqual(1, allMembersFromStore.Count(), "There should be exact 1 member");

            Assert.AreEqual(allAuctionFromStore.FirstOrDefault().Seller, allMembersFromStore.FirstOrDefault());
            Assert.AreEqual(allMembersFromStore.FirstOrDefault().Auctions.FirstOrDefault(), allAuctionFromStore.FirstOrDefault());
        }
    }
}
{'fraction_non_alphanumeric': 0.08705769625624529, 'fraction_numerical': 0.001984805968106221, 'mean_word_length': 2.1389903329752955, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4258574', 'n_tokens_mistral': 3867, 'n_tokens_neox': 3648, 'n_words': 717}