public void SearchForPlayerById()
        {
            //Arrange
            var id       = new ObjectId();
            var uniqueId = new BsonObjectId(id);

            var playerToFind = new Player()
            {
                Id     = uniqueId,
                Name   = "Falsum Hominem",
                Losses = 1,
                Wins   = 2,
            };

            var mockRepo = new Mock <IRepository <IPlayer> >();

            mockRepo.Setup(x => x.FindById(playerToFind.Id)).
            Returns(playerToFind);

            var playerService = new PlayerService(mockRepo.Object);

            //Act
            var playerReturned = playerService.SearchById(playerToFind.Id);

            //Assert
            playerReturned.Should().Be(playerToFind);
        }
示例#2
0
        public static Transfer New(string tableName, string className)
        {
            MongoDB.Bson.BsonObjectId bsonObjectId = MongoDB.Bson.BsonObjectId.GenerateNewId();
            Transfer transfer = new Transfer();

            transfer.m_ObjectId                           = bsonObjectId.ToString();
            transfer.m_TableName                          = tableName;
            transfer.m_HasCLSObjectId                     = false;
            transfer.m_HasSQLObjectId                     = false;
            transfer.m_HasSQLTimestamp                    = false;
            transfer.m_TimestampColumnName                = null;
            transfer.m_HasTransferDBTSAttribute           = false;
            transfer.m_TransferDBTS                       = null;
            transfer.m_HasSQLDeleteTrigger                = false;
            transfer.m_SQLRowCount                        = 0;
            transfer.m_MongoDocumentCount                 = 0;
            transfer.m_SQLNullObjectIdCount               = 0;
            transfer.m_OutOfSyncCount                     = 0;
            transfer.m_SQLIndexCount                      = 0;
            transfer.m_MongoIndexCount                    = 0;
            transfer.m_HasBaseClass                       = false;
            transfer.m_BaseTableName                      = null;
            transfer.m_ExtendedDocumentCount              = 0;
            transfer.m_HasTransferStraightAcrossAttribute = false;
            transfer.m_TransferStraightAcross             = false;
            return(transfer);
        }
        public void GameOutcome()
        {
            //Arrange
            var id       = new ObjectId();
            var uniqueId = new BsonObjectId(id);

            var playerOne = new Player()
            {
                Id     = uniqueId,
                Name   = "Falsum Hominem",
                Losses = 1,
                Wins   = 2,
            };

            var mockRepo = new Mock <IRepository <IPlayer> >();

            mockRepo.Setup(x => x.FindByUsername("Falsum Hominem")).Returns(playerOne);

            var gameService = new GameService(mockRepo.Object);
            var winner      = "Falsum Hominem";
            var loser       = "Falsum Hominem";

            //Act
            var game = gameService.Add(winner, loser);

            //Assert
            game.Winner.Should().Be(playerOne.Id);
            game.Loser.Should().Be(playerOne.Id);
        }
示例#4
0
 public AccountDeletedEventArgs(Account data, MongoDB.Bson.BsonObjectId id) : base(data)
 {
     this.Id = id;
 }
        // private static methods
        private static BsonValue Convert(object value, Conversion conversion)
        {
            // note: the ToBoolean conversions use the JavaScript definition of truthiness
            switch (conversion)
            {
            // note: I expect this switch statement to be compiled using a jump table and therefore to be very efficient
            case Conversion.None: return((BsonValue)value);

            case Conversion.ByteArrayToBsonBinary: return(new BsonBinaryData((byte[])value));

            case Conversion.ByteArrayToBsonObjectId: return(BsonObjectId.Create((byte[])value));

            case Conversion.ByteToBsonBoolean: return(BsonBoolean.Create((byte)value != 0));

            case Conversion.ByteToBsonDouble: return(new BsonDouble((double)(byte)value));

            case Conversion.ByteToBsonInt32: return(BsonInt32.Create((int)(byte)value));

            case Conversion.ByteToBsonInt64: return(new BsonInt64((long)(byte)value));

            case Conversion.CharToBsonBoolean: return(BsonBoolean.Create((char)value != 0));

            case Conversion.CharToBsonDouble: return(new BsonDouble((double)(char)value));

            case Conversion.CharToBsonInt32: return(BsonInt32.Create((int)(char)value));

            case Conversion.CharToBsonInt64: return(new BsonInt64((long)(char)value));

            case Conversion.DateTimeOffsetToBsonDateTime: return(new BsonDateTime(((DateTimeOffset)value).UtcDateTime));

            case Conversion.DateTimeToBsonDateTime: return(new BsonDateTime((DateTime)value));

            case Conversion.DoubleToBsonBoolean: var d = (double)value; return(BsonBoolean.Create(!(double.IsNaN(d) || d == 0.0)));

            case Conversion.GuidToBsonBinary: return(new BsonBinaryData((Guid)value));

            case Conversion.Int16ToBsonBoolean: return(BsonBoolean.Create((short)value != 0));

            case Conversion.Int16ToBsonDouble: return(new BsonDouble((double)(short)value));

            case Conversion.Int16ToBsonInt32: return(BsonInt32.Create((int)(short)value));

            case Conversion.Int16ToBsonInt64: return(new BsonInt64((long)(short)value));

            case Conversion.Int32ToBsonBoolean: return(BsonBoolean.Create((int)value != 0));

            case Conversion.Int32ToBsonDouble: return(new BsonDouble((double)(int)value));

            case Conversion.Int32ToBsonInt64: return(new BsonInt64((long)(int)value));

            case Conversion.Int64ToBsonBoolean: return(BsonBoolean.Create((long)value != 0));

            case Conversion.Int64ToBsonDouble: return(new BsonDouble((double)(long)value));

            case Conversion.Int64ToBsonTimestamp: return(new BsonTimestamp((long)value));

            case Conversion.BsonMaxKeyToBsonBoolean: return(BsonBoolean.True);

            case Conversion.BsonMinKeyToBsonBoolean: return(BsonBoolean.True);

            case Conversion.NewBsonBoolean: return(BsonBoolean.Create((bool)value));

            case Conversion.NewBsonDouble: return(new BsonDouble((double)value));

            case Conversion.NewBsonInt32: return(BsonInt32.Create((int)value));

            case Conversion.NewBsonInt64: return(new BsonInt64((long)value));

            case Conversion.NewBsonObjectId: return(new BsonObjectId((ObjectId)value));

            case Conversion.NewBsonString: return(new BsonString((string)value));

            case Conversion.BsonNullToBsonBoolean: return(BsonBoolean.False);

            case Conversion.RegexToBsonRegularExpression: return(new BsonRegularExpression((Regex)value));

            case Conversion.SByteToBsonBoolean: return(BsonBoolean.Create((sbyte)value != 0));

            case Conversion.SByteToBsonDouble: return(new BsonDouble((double)(sbyte)value));

            case Conversion.SByteToBsonInt32: return(BsonInt32.Create((int)(sbyte)value));

            case Conversion.SByteToBsonInt64: return(new BsonInt64((long)(sbyte)value));

            case Conversion.SingleToBsonBoolean: var f = (float)value; return(BsonBoolean.Create(!(float.IsNaN(f) || f == 0.0f)));

            case Conversion.SingleToBsonDouble: return(new BsonDouble((double)(float)value));

            case Conversion.StringToBsonBoolean: return(BsonBoolean.Create((string)value != ""));

            case Conversion.StringToBsonDateTime:
                var formats = new string[] { "yyyy-MM-ddK", "yyyy-MM-ddTHH:mm:ssK", "yyyy-MM-ddTHH:mm:ss.FFFFFFFK" };
                var dt      = DateTime.ParseExact((string)value, formats, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
                return(new BsonDateTime(dt));

            case Conversion.StringToBsonDouble: return(new BsonDouble(XmlConvert.ToDouble((string)value)));

            case Conversion.StringToBsonInt32: return(BsonInt32.Create(XmlConvert.ToInt32((string)value)));

            case Conversion.StringToBsonInt64: return(new BsonInt64(XmlConvert.ToInt64((string)value)));

            case Conversion.StringToBsonJavaScript: return(new BsonJavaScript((string)value));

            case Conversion.StringToBsonJavaScriptWithScope: return(new BsonJavaScriptWithScope((string)value, new BsonDocument()));

            case Conversion.StringToBsonObjectId: return(BsonObjectId.Create((string)value));

            case Conversion.StringToBsonRegularExpression: return(new BsonRegularExpression((string)value));

            case Conversion.StringToBsonSymbol: return(BsonSymbol.Create((string)value));

            case Conversion.StringToBsonTimestamp: return(new BsonTimestamp(XmlConvert.ToInt64((string)value)));

            case Conversion.UInt16ToBsonBoolean: return(BsonBoolean.Create((ushort)value != 0));

            case Conversion.UInt16ToBsonDouble: return(new BsonDouble((double)(ushort)value));

            case Conversion.UInt16ToBsonInt32: return(BsonInt32.Create((int)(ushort)value));

            case Conversion.UInt16ToBsonInt64: return(new BsonInt64((long)(ushort)value));

            case Conversion.UInt32ToBsonBoolean: return(BsonBoolean.Create((uint)value != 0));

            case Conversion.UInt32ToBsonDouble: return(new BsonDouble((double)(uint)value));

            case Conversion.UInt32ToBsonInt32: return(BsonInt32.Create((int)(uint)value));

            case Conversion.UInt32ToBsonInt64: return(new BsonInt64((long)(uint)value));

            case Conversion.UInt64ToBsonBoolean: return(BsonBoolean.Create((ulong)value != 0));

            case Conversion.UInt64ToBsonDouble: return(new BsonDouble((double)(ulong)value));

            case Conversion.UInt64ToBsonInt64: return(new BsonInt64((long)(ulong)value));

            case Conversion.UInt64ToBsonTimestamp: return(new BsonTimestamp((long)(ulong)value));
            }

            throw new BsonInternalException("Unexpected Conversion.");
        }
示例#6
0
        private void Dodaj_Load(object sender, EventArgs e)
        {
            if (kat == "Prenosni racunari")
            {
                Prenosni_Racunari p1 = new Prenosni_Racunari();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Prenosni_Racunari>("Prenosni_Racunari");
                    var rez          = collectionPR.AsQueryable <Prenosni_Racunari>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text  = pp.Proizvodjac;
                        txtbox2.Text  = pp.Naziv;
                        txtbox3.Text  = pp.Model;
                        txtbox4.Text  = pp.RAM;
                        txtbox5.Text  = pp.Procesor;
                        txtbox6.Text  = pp.Graficka_Kartica;
                        txtbox7.Text  = pp.Hard_Disk;
                        txtbox8.Text  = pp.Dijagona_Ekrana;
                        txtbox9.Text  = pp.Kamera;
                        txtbox10.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Racunari")
            {
                Racunari p1 = new Racunari();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Racunari>("Racunari");
                    var rez          = collectionPR.AsQueryable <Racunari>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text  = pp.Proizvodjac;
                        txtbox2.Text  = pp.Naziv;
                        txtbox3.Text  = pp.RAM;
                        txtbox4.Text  = pp.Model;
                        txtbox5.Text  = pp.Procesor;
                        txtbox6.Text  = pp.Maticna_Ploca;
                        txtbox7.Text  = pp.Napajanje;
                        txtbox8.Text  = pp.Graficka_Kartica;
                        txtbox9.Text  = pp.Hard_Disk;
                        txtbox10.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Mobilni uredjaji")
            {
                Mobilni_Uredjaji p1 = new Mobilni_Uredjaji();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Mobilni_Uredjaji>("Mobilni_Uredjaji");
                    var rez          = collectionPR.AsQueryable <Mobilni_Uredjaji>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.RAM;
                        txtbox5.Text = pp.Procesor;
                        txtbox6.Text = pp.Dijagona_Ekrana;
                        txtbox7.Text = pp.Kamera;
                        txtbox8.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Misevi")
            {
                Racunarska_Oprema p1 = new Racunarska_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[6].Text = "DPI";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Racunarska_Oprema>("Racunarska_Oprema");
                    var rez          = collectionPR.AsQueryable <Racunarska_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Povezanost;
                        txtbox6.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Tastature")
            {
                Racunarska_Oprema p1 = new Racunarska_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[6].Text = "Odziv";
                labele[7].Text = "Vodootpornost";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Racunarska_Oprema>("Racunarska_Oprema");
                    var rez          = collectionPR.AsQueryable <Racunarska_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Povezanost;
                        txtbox6.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Web kamere")
            {
                Racunarska_Oprema p1 = new Racunarska_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[6].Text = "MPX";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Racunarska_Oprema>("Racunarska_Oprema");
                    var rez          = collectionPR.AsQueryable <Racunarska_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Povezanost;
                        txtbox6.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Slusalice")
            {
                Audio_Oprema p1 = new Audio_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[5].Text = "Noice canceling";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Audio_Oprema>("Audio_Oprema");
                    var rez          = collectionPR.AsQueryable <Audio_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Zvucnici")
            {
                Audio_Oprema p1 = new Audio_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[5].Text = "Izlazna snaga";
                labele[6].Text = "Materijal izrade";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Audio_Oprema>("Audio_Oprema");
                    var rez          = collectionPR.AsQueryable <Audio_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Cena;
                        idd          = pp.Id;
                    }
                }
            }
            if (kat == "Mikrofoni")
            {
                Audio_Oprema p1 = new Audio_Oprema();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[5].Text = "Range";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Audio_Oprema>("Audio_Oprema");
                    var rez          = collectionPR.AsQueryable <Audio_Oprema>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Tip;
                        txtbox5.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Monitori")
            {
                Monitori p1 = new Monitori();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Monitori>("Monitori");
                    var rez          = collectionPR.AsQueryable <Monitori>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Dijagona_Ekrana;
                        txtbox5.Text = pp.Panel;
                        txtbox6.Text = pp.Odaziv;
                        txtbox7.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Stampaci")
            {
                Stampaci_i_Skeneri p1 = new Stampaci_i_Skeneri();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }
                labele[6].Text = "U boji ?";

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Stampaci_i_Skeneri>("Stampaci_i_Skeneri");
                    var rez          = collectionPR.AsQueryable <Stampaci_i_Skeneri>().Where(x => x.Model == modell).ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Format;
                        txtbox5.Text = pp.Tip;
                        txtbox6.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }
            if (kat == "Skeneri")
            {
                Stampaci_i_Skeneri p1 = new Stampaci_i_Skeneri();
                System.Reflection.PropertyInfo[] properti = p1.GetType().GetProperties();
                for (int i = 0; i < properti.Length - 2; i++)
                {
                    labele[i].Text = properti[i + 1].Name;
                }

                if (update_da == "da")
                {
                    var client = new MongoClient("mongodb://localhost/?safe=true");
                    var db     = client.GetDatabase("Katalog");

                    var collectionPR = db.GetCollection <Stampaci_i_Skeneri>("Stampaci_i_Skeneri");
                    var rez          = collectionPR.AsQueryable <Stampaci_i_Skeneri>().ToList();
                    foreach (var pp in rez)
                    {
                        txtbox1.Text = pp.Proizvodjac;
                        txtbox2.Text = pp.Naziv;
                        txtbox3.Text = pp.Model;
                        txtbox4.Text = pp.Format;
                        txtbox5.Text = pp.Tip;
                        txtbox6.Text = pp.Cena;

                        idd = pp.Id;
                    }
                }
            }



            if (lbl1.Text == "")
            {
                txtbox1.Visible = false;
            }
            if (lbl2.Text == "")
            {
                txtbox2.Visible = false;
            }
            if (lbl3.Text == "")
            {
                txtbox3.Visible = false;
            }
            if (lbl4.Text == "")
            {
                txtbox4.Visible = false;
            }
            if (lbl5.Text == "")
            {
                txtbox5.Visible = false;
            }
            if (lbl6.Text == "")
            {
                txtbox6.Visible = false;
            }
            if (lbl7.Text == "")
            {
                txtbox7.Visible = false;
            }
            if (lbl8.Text == "")
            {
                txtbox8.Visible = false;
            }
            if (lbl9.Text == "")
            {
                txtbox9.Visible = false;
            }
            if (lbl10.Text == "")
            {
                txtbox10.Visible = false;
            }
        }
示例#7
0
 public static dynamic ToDynamic(this BsonObjectId bsonObjectId) => bsonObjectId.ToString();